From e677f07d4674afda848e9c244d1f6ee3df77358a Mon Sep 17 00:00:00 2001 From: leventov Date: Fri, 4 Mar 2016 21:02:58 +0700 Subject: [PATCH] Use Data.equivalent() method in KeySearch.keyEquals() (because it could be specialized to perform more efficiently), and switch arguments in Data.bytesEquivalent() usages, so that the first Data instance is more likely to optimized for comparison --- src/main/java/net/openhft/chronicle/hash/Data.java | 2 +- .../openhft/chronicle/hash/impl/stage/query/KeySearch.java | 4 +--- src/main/java/net/openhft/chronicle/map/MapMethods.java | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/Data.java b/src/main/java/net/openhft/chronicle/hash/Data.java index a7dfbc399..32dfe5d94 100644 --- a/src/main/java/net/openhft/chronicle/hash/Data.java +++ b/src/main/java/net/openhft/chronicle/hash/Data.java @@ -34,7 +34,7 @@ import static net.openhft.chronicle.algo.bytes.Access.checkedRandomDataInputAcce *

In most cases, each particular value wraps either some object or some bytes. Object * is marshalled to bytes lazily on demand, and bytes are lazily deserialized to object, * accordingly. - * + * * @param type of the accessed objects */ public interface Data { diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/KeySearch.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/KeySearch.java index 52c5a7816..93c5a59b4 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/query/KeySearch.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/query/KeySearch.java @@ -84,9 +84,7 @@ public abstract class KeySearch { } boolean keyEquals(long keySize, long keyOffset) { - return inputKey.size() == keySize && - BytesUtil.bytesEqual(s.segmentBS, keyOffset, - inputKey.bytes(), inputKey.offset(), keySize); + return inputKey.size() == keySize && inputKey.equivalent(s.segmentBS, keyOffset); } public boolean searchStatePresent() { diff --git a/src/main/java/net/openhft/chronicle/map/MapMethods.java b/src/main/java/net/openhft/chronicle/map/MapMethods.java index 5c803103c..8c954bf7b 100644 --- a/src/main/java/net/openhft/chronicle/map/MapMethods.java +++ b/src/main/java/net/openhft/chronicle/map/MapMethods.java @@ -238,7 +238,7 @@ public interface MapMethods { // as in putIfAbsent()/acquireUsing(), start with update lock: q.updateLock().lock(); MapEntry entry = q.entry(); - if (entry != null && bytesEquivalent(entry.value(), value)) { + if (entry != null && bytesEquivalent(value, entry.value())) { q.remove(entry); return true; } else { @@ -298,7 +298,7 @@ public interface MapMethods { // as in putIfAbsent()/acquireUsing(), start with update lock: q.updateLock().lock(); MapEntry entry = q.entry(); - if (entry != null && bytesEquivalent(((MapEntry) entry).value(), oldValue)) { + if (entry != null && bytesEquivalent(oldValue, entry.value())) { q.replaceValue(entry, newValue); return true; } else {