optimized BitArray.equals

This commit is contained in:
Sergey Chernov 2025-09-26 20:06:54 +04:00
parent 3481a718b1
commit e8b630715a
2 changed files with 8 additions and 2 deletions

View File

@ -183,7 +183,7 @@ class Script(
catch( e: ExecutionError ) { catch( e: ExecutionError ) {
e.errorObject e.errorObject
} }
catch (e: ScriptError) { catch (_: ScriptError) {
ObjNull ObjNull
} }
result ?: raiseError(ObjAssertionFailedException(this,"Expected exception but nothing was thrown")) result ?: raiseError(ObjAssertionFailedException(this,"Expected exception but nothing was thrown"))

View File

@ -81,7 +81,13 @@ class BitArray(val bytes: UByteArray, val lastByteBits: Int) : BitList {
fun asUByteArray(): UByteArray = bytes fun asUByteArray(): UByteArray = bytes
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
return other is BitList && this.compareTo(other) == 0 return when(other) {
is BitArray ->
// important: size must match as trailing zero bits will generate false eq otherwise:
size == other.size && bytes contentEquals other.bytes
is BitList -> compareTo(other) == 0
else -> false
}
} }
override fun hashCode(): Int { override fun hashCode(): Int {