DonalEvans commented on a change in pull request #6699:
URL: https://github.com/apache/geode/pull/6699#discussion_r674378002



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -173,20 +176,23 @@ public int getDSFID() {
   }
 
   protected synchronized byte[] memberAdd(byte[] memberToAdd, byte[] 
scoreToAdd) {
-    byte[] oldScore = null;
-
-    OrderedSetEntry newEntry = new OrderedSetEntry(memberToAdd, scoreToAdd);
-    OrderedSetEntry orderedSetEntry = members.put(memberToAdd, newEntry);
-    if (orderedSetEntry == null) {
+    OrderedSetEntry existingEntry = members.get(memberToAdd);
+    if (existingEntry == null) {
+      OrderedSetEntry newEntry = new OrderedSetEntry(memberToAdd, scoreToAdd);
+      members.put(memberToAdd, newEntry);
       scoreSet.add(newEntry);
-      sizeInBytes += calculateSizeOfFieldValuePair(memberToAdd, scoreToAdd);
+      // Without this adjustment, we count the entry and member name array 
twice, since references
+      // to them appear in both backing collections.
+      sizeInBytesAdjustment += newEntry.getSizeInBytes() + 
calculateByteArraySize(memberToAdd);
+      return null;
     } else {
-      scoreSet.remove(orderedSetEntry);
-      scoreSet.add(newEntry);
-      oldScore = orderedSetEntry.getScoreBytes();
-      sizeInBytes += scoreToAdd.length - oldScore.length;
+      scoreSet.remove(existingEntry);
+      byte[] oldScore = existingEntry.scoreBytes;
+      existingEntry.updateScore(stripTrailingZeroFromDouble(scoreToAdd));
+      members.put(memberToAdd, existingEntry);

Review comment:
       Filed GEODE-9446 to track the refactoring work.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to