Committed by
Gerrit Code Review
ECMap: synchronization free removeInternal
Change-Id: I89b88d11b830de5ceb97fdc3fb91ae51bc1bb1cb
Showing
1 changed file
with
13 additions
and
5 deletions
... | @@ -295,14 +295,22 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -295,14 +295,22 @@ public class EventuallyConsistentMapImpl<K, V> |
295 | } | 295 | } |
296 | 296 | ||
297 | private boolean removeInternal(K key, Timestamp timestamp) { | 297 | private boolean removeInternal(K key, Timestamp timestamp) { |
298 | - synchronized (this) { | 298 | + Timestamped<V> value = items.get(key); |
299 | - if (items.get(key) != null && items.get(key).isNewer(timestamp)) { | 299 | + if (value != null) { |
300 | + if (value.isNewer(timestamp)) { | ||
300 | return false; | 301 | return false; |
302 | + } else { | ||
303 | + items.remove(key, value); | ||
304 | + } | ||
301 | } | 305 | } |
302 | 306 | ||
303 | - items.remove(key); | 307 | + Timestamp removedTimestamp = removedItems.get(key); |
304 | - removedItems.put(key, timestamp); | 308 | + if (removedTimestamp == null) { |
305 | - return true; | 309 | + return removedItems.putIfAbsent(key, timestamp) == null; |
310 | + } else if (timestamp.compareTo(removedTimestamp) > 0) { | ||
311 | + return removedItems.replace(key, removedTimestamp, timestamp); | ||
312 | + } else { | ||
313 | + return false; | ||
306 | } | 314 | } |
307 | } | 315 | } |
308 | 316 | ... | ... |
-
Please register or login to post a comment