aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-09-07 11:38:58 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-09-08 10:37:54 +0200
commitd4752e2900ac4c12fafa16ba91cbaa62467db7c2 (patch)
tree2c0e1bc93c048a6d0c7ece78cb90c2ba37ebf270
parent1fd09a19a2ac7d8953ea0abed81d906aef197bab (diff)
downloadjgit-d4752e2900ac4c12fafa16ba91cbaa62467db7c2.tar.gz
jgit-d4752e2900ac4c12fafa16ba91cbaa62467db7c2.zip
[error prone] Suppress NonAtomicVolatileUpdate in SimpleLruCache
We don't need to update time atomically since it's only used to order cache entries in LRU order. Change-Id: I756fa6d90b180c519bf52925f134763744f2c1f1 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SimpleLruCache.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SimpleLruCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SimpleLruCache.java
index 709d9ee73d..3fcfd21fc5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SimpleLruCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SimpleLruCache.java
@@ -162,7 +162,7 @@ public class SimpleLruCache<K, V> {
public V get(Object key) {
Entry<K, V> entry = map.get(key);
if (entry != null) {
- entry.lastAccessed = ++time;
+ entry.lastAccessed = tick();
return entry.value;
}
return null;
@@ -186,13 +186,18 @@ public class SimpleLruCache<K, V> {
* if the specified key or value is null
*/
public V put(@NonNull K key, @NonNull V value) {
- map.put(key, new Entry<>(key, value, ++time));
+ map.put(key, new Entry<>(key, value, tick()));
if (map.size() > maximumSize) {
purge();
}
return value;
}
+ @SuppressWarnings("NonAtomicVolatileUpdate")
+ private long tick() {
+ return ++time;
+ }
+
/**
* Returns the current size of this cache
*