Inline Entry.contains() 60/98360/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Nov 2021 08:22:45 +0000 (09:22 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Nov 2021 08:25:52 +0000 (09:25 +0100)
MutableUnsignedLongSet.add() has half of the check done in contains()
as an invariant. Inline the second part there, improving performance a
bit.

Thisleaves only UnsignedLongSet.contains() as the sole caller of
Entry.contains(). Inline it there, reducing the footprint a bit.

JIRA: CONTROLLER-2014
Change-Id: Ie38283a1fc46aff8fbc717a23aa9a068805636db
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/MutableUnsignedLongSet.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/UnsignedLongSet.java

index 6fdb04f1fe50b3316278f4afb529751fb0307a2c..689baad40b8225a5c2bb2f53145ca54dd2d07801 100644 (file)
@@ -38,7 +38,8 @@ public final class MutableUnsignedLongSet extends UnsignedLongSet implements Mut
         final var headIt = ranges.headSet(range, true).descendingIterator();
         if (headIt.hasNext()) {
             final var head = headIt.next();
         final var headIt = ranges.headSet(range, true).descendingIterator();
         if (headIt.hasNext()) {
             final var head = headIt.next();
-            if (head.contains(longBits)) {
+            if (Long.compareUnsigned(head.upperBits, longBits) >= 0) {
+                // Already contained, this is a no-op
                 return;
             }
 
                 return;
             }
 
index daf958a987eece6b262bf1d729ac2ce012d31c45..14e3b6a41fce6e681b95c38ebe945fdbf5a6388f 100644 (file)
@@ -67,10 +67,6 @@ abstract class UnsignedLongSet {
             return UnsignedLong.fromLongBits(upperBits);
         }
 
             return UnsignedLong.fromLongBits(upperBits);
         }
 
-        boolean contains(final long longBits) {
-            return Long.compareUnsigned(lowerBits, longBits) <= 0 && Long.compareUnsigned(upperBits, longBits) >= 0;
-        }
-
         Entry copy() {
             return new Entry(lowerBits, upperBits);
         }
         Entry copy() {
             return new Entry(lowerBits, upperBits);
         }
@@ -139,7 +135,9 @@ abstract class UnsignedLongSet {
 
     public final boolean contains(final long longBits) {
         final var head = ranges.floor(Entry.of(longBits));
 
     public final boolean contains(final long longBits) {
         final var head = ranges.floor(Entry.of(longBits));
-        return head != null && head.contains(longBits);
+        return head != null
+            && Long.compareUnsigned(head.lowerBits, longBits) <= 0
+            && Long.compareUnsigned(head.upperBits, longBits) >= 0;
     }
 
     public final boolean isEmpty() {
     }
 
     public final boolean isEmpty() {