Skip to content

Commit

Permalink
core: simplify id compare (#1694)
Browse files Browse the repository at this point in the history
Use Arrays utility method for comparing the byte arrays.
  • Loading branch information
brharrington authored Sep 26, 2024
1 parent b02bc9d commit 8c8edfc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@ class ItemId private (private val data: Array[Byte], private val hc: Int)
}

override def compareTo(other: ItemId): Int = {
val length = math.min(data.length, other.data.length)
var i = 0
while (i < length) {
val b1 = java.lang.Byte.toUnsignedInt(data(i))
val b2 = java.lang.Byte.toUnsignedInt(other.data(i))
val cmp = b1 - b2
if (cmp != 0) return cmp
i += 1
}
0
java.util.Arrays.compareUnsigned(data, other.data)
}

override def toString: String = {
Expand Down Expand Up @@ -80,13 +71,6 @@ class ItemId private (private val data: Array[Byte], private val hc: Int)
}
result
}

/**
* Returns the byte array representing the id. This accessor is only provided to allow
* for serialization without additional allocations. The returned array should not be
* modified.
*/
def byteArrayUnsafe: Array[Byte] = data
}

object ItemId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ class ItemIdCalculator {

object ItemIdCalculator {

type Pair = (String, String)

private val emptyId = ItemId(Hash.sha1bytes(""))

// Large enough for most key/value pairs
Expand Down

0 comments on commit 8c8edfc

Please sign in to comment.