From e2ba8b3f5a14b5ca4307872d8ac3eb17c96997ff Mon Sep 17 00:00:00 2001 From: leventov Date: Mon, 14 Dec 2015 13:54:04 +0300 Subject: [PATCH 1/2] HCOLL-410 --- .../chronicle/map/ReplicatedChronicleMap.java | 12 ++++----- .../chronicle/map/VanillaChronicleMap.java | 25 ++++++------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 3e5b52b77..17a5281ba 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -929,12 +929,12 @@ final class ReplicatedChronicleMap, SearchState searchState = segmentState.searchState; hashLookup.startSearch(hash2, searchState); MultiStoreBytes entry = segmentState.tmpBytes; - boolean hasValueChanged = false; for (long pos; (pos = hashLookup.nextPos(searchState)) >= 0L; ) { long offset = offsetFromPos(pos); reuse(entry, offset); @@ -2195,8 +2194,6 @@ class VanillaChronicleMap, } else { long valueAddr = entry.positionAddr(); long entryEndAddr = valueAddr + prevValueSize; - hasValueChanged = prevValueSize != valueSize || - !metaValueInterop.startsWith(valueInterop, entry, value); // putValue may relocate entry and change offset putValue(pos, entry, valueSizePos, entryEndAddr, false, segmentState, @@ -2207,11 +2204,13 @@ class VanillaChronicleMap, } // put callbacks + boolean hasValueChanged = updateResult != UpdateResult.UNCHANGED; onPutMaybeRemote(segmentState.pos, false); - if (bytesEventListener != null) - bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, false, hasValueChanged); + if (bytesEventListener != null) { + bytesEventListener.onPut(entry, 0L, metaDataBytes, valueSizePos, false, + false, hasValueChanged); + } if (eventListener != null) { - eventListener.onPut(toKey.toInstance(copies, key, keySize), toValue.toInstance(copies, value, valueSize), null, false, false, hasValueChanged, @@ -2232,7 +2231,7 @@ class VanillaChronicleMap, onPut(this, segmentState.pos); if (bytesEventListener != null) bytesEventListener.onPut(entry, 0L, metaDataBytes, - segmentState.valueSizePos, true, false, hasValueChanged); + segmentState.valueSizePos, true, false, true); if (eventListener != null) { byte replacedIdentifier = 0; long replacedTimeStamp = 0; @@ -2310,29 +2309,19 @@ class VanillaChronicleMap, } } - // key is not found VBI valueInterop = getValueInterops.getValueInterop(copies); MVBI metaValueInterop = getValueInterops.getMetaValueInterop(copies, valueInterop, value); - long valueSize = putEntry(segmentState, metaKeyInterop, keyInterop, key, keySize, metaValueInterop, valueInterop, value, entry, false); - - boolean hasValueChanged = false; - if (eventListener != null || bytesEventListener != null) { - // todo roman to check this - hasValueChanged = - !metaValueInterop.startsWith(valueInterop, entry, value); - } - // put callbacks onPut(this, segmentState.pos); if (bytesEventListener != null) bytesEventListener.onPut(entry, 0L, metaDataBytes, - segmentState.valueSizePos, true, false, hasValueChanged); + segmentState.valueSizePos, true, false, true); if (eventListener != null) eventListener.onPut(toKey.toInstance(copies, key, keySize), toValue.toInstance(copies, value, valueSize), null, false, true, true, From d0dc667717d8126f7938d7d4100b6ffa1c9513c0 Mon Sep 17 00:00:00 2001 From: leventov Date: Mon, 14 Dec 2015 13:56:55 +0300 Subject: [PATCH 2/2] Improve startsWith() implementations --- .../serialization/internal/BasicCopyingMetaBytesInterop.java | 2 +- .../java/net/openhft/chronicle/map/VanillaChronicleMap.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java index 250cd18f8..450d067a9 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java @@ -52,7 +52,7 @@ public abstract class BasicCopyingMetaBytesInterop implements MetaBytesInt @Override public boolean startsWith(W writer, Bytes bytes, E e) { - return bytes.startsWith(buffer.buffer); + return BytesBytesInterop.INSTANCE.startsWith(bytes, buffer.buffer); } @Override diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index c1f3b0d8b..0cf1c1a86 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -1354,7 +1354,7 @@ class VanillaChronicleMap, @Override public boolean startsWith(Void interop, Bytes bytes, Bytes value) { - return bytes.startsWith(value); + return BytesBytesInterop.INSTANCE.startsWith(bytes, value); } @Override