Tune LString.equals() and related functions.

This commit is contained in:
James Roseborough
2009-04-18 18:34:28 +00:00
parent 0d0236819d
commit beef2f99a0

View File

@@ -45,8 +45,8 @@ import java.io.OutputStream;
*/ */
public class LString extends LValue { public class LString extends LValue {
public final byte[] m_bytes; public byte[] m_bytes;
public final int m_offset; public int m_offset;
public final int m_length; public final int m_length;
public final int m_hash; public final int m_hash;
@@ -178,14 +178,26 @@ public class LString extends LValue {
public boolean isString() { public boolean isString() {
return true; return true;
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o )
return true;
if ( o != null && o instanceof LString ) { if ( o != null && o instanceof LString ) {
LString s = (LString) o; LString s = (LString) o;
return m_hash == s.m_hash && if ( m_hash == s.m_hash && m_length == s.m_length ) {
m_length == s.m_length && if ( m_bytes == s.m_bytes && m_offset == s.m_offset )
( ( m_bytes == s.m_bytes && m_offset == s.m_offset ) || return true;
equals( m_bytes, m_offset, s.m_bytes, s.m_offset, m_length ) ); if ( equals( m_bytes, m_offset, s.m_bytes, s.m_offset, m_length ) ) {
if ( m_bytes.length < s.m_bytes.length ) {
s.m_bytes = m_bytes;
s.m_offset = m_offset;
} else {
m_bytes = s.m_bytes;
m_offset = s.m_offset;
}
return true;
}
}
} }
return false; return false;
} }
@@ -429,12 +441,9 @@ public class LString extends LValue {
public static boolean equals( byte[] a, int i, byte[] b, int j, int n ) { public static boolean equals( byte[] a, int i, byte[] b, int j, int n ) {
if ( a.length < i + n || b.length < j + n ) if ( a.length < i + n || b.length < j + n )
return false; return false;
final int imax = i + n; while ( --n>=0 )
final int jmax = j + n; if ( a[i++]!=b[j++] )
while ( i < imax && j < jmax ) {
if ( a[i++] != b[j++] )
return false; return false;
}
return true; return true;
} }