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 final byte[] m_bytes;
public final int m_offset;
public byte[] m_bytes;
public int m_offset;
public final int m_length;
public final int m_hash;
@@ -180,12 +180,24 @@ public class LString extends LValue {
}
public boolean equals(Object o) {
if ( this == o )
return true;
if ( o != null && o instanceof LString ) {
LString s = (LString) o;
return m_hash == s.m_hash &&
m_length == s.m_length &&
( ( m_bytes == s.m_bytes && m_offset == s.m_offset ) ||
equals( m_bytes, m_offset, s.m_bytes, s.m_offset, m_length ) );
if ( m_hash == s.m_hash && m_length == s.m_length ) {
if ( m_bytes == s.m_bytes && m_offset == s.m_offset )
return true;
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;
}
@@ -429,12 +441,9 @@ public class LString extends LValue {
public static boolean equals( byte[] a, int i, byte[] b, int j, int n ) {
if ( a.length < i + n || b.length < j + n )
return false;
final int imax = i + n;
final int jmax = j + n;
while ( i < imax && j < jmax ) {
while ( --n>=0 )
if ( a[i++]!=b[j++] )
return false;
}
return true;
}