Make compareTo of bytestring faster

This commit is contained in:
DBotThePony 2024-04-18 14:51:49 +07:00
parent de735cc5b8
commit 32b8c4e6d5
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 16 additions and 0 deletions

View File

@ -87,6 +87,14 @@ class ArrayByteString extends ByteString {
return hc;
}
@Override
public int compareTo(ByteString that) {
if (that instanceof ArrayByteString bstring)
return Arrays.compare(bytes, bstring.bytes);
return super.compareTo(that);
}
@Override
int maybeHashCode() {
return hashCode;

View File

@ -96,6 +96,14 @@ class StringByteString extends ByteString {
return thisIterator.hasNext() == thatIterator.hasNext();
}
@Override
public int compareTo(ByteString that) {
if (that instanceof StringByteString bstring)
return string.compareTo(bstring.string);
return super.compareTo(that);
}
private int computeHashCode() {
int hc = 0;