From 8c8edfc3223e44d2aa8cac19ec0ce9f2654f2a1a Mon Sep 17 00:00:00 2001 From: brharrington Date: Thu, 26 Sep 2024 16:42:51 -0500 Subject: [PATCH] core: simplify id compare (#1694) Use Arrays utility method for comparing the byte arrays. --- .../com/netflix/atlas/core/model/ItemId.scala | 18 +----------------- .../atlas/core/model/ItemIdCalculator.scala | 2 -- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemId.scala b/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemId.scala index 954a1f8ac..4fe3aae30 100644 --- a/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemId.scala +++ b/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemId.scala @@ -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 = { @@ -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 { diff --git a/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemIdCalculator.scala b/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemIdCalculator.scala index 627da8115..fbdf7eb7f 100644 --- a/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemIdCalculator.scala +++ b/atlas-core/src/main/scala/com/netflix/atlas/core/model/ItemIdCalculator.scala @@ -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