@@ -2188,7 +2188,7 @@ V waitForLoadingValue(ReferenceEntry<K, V> e, K key, ValueReference<K, V> valueR
2188
2188
V compute (K key , int hash , BiFunction <? super K , ? super V , ? extends V > function ) {
2189
2189
ReferenceEntry <K , V > e ;
2190
2190
ValueReference <K , V > valueReference = null ;
2191
- LoadingValueReference <K , V > loadingValueReference = null ;
2191
+ ComputingValueReference <K , V > computingValueReference = null ;
2192
2192
boolean createNewEntry = true ;
2193
2193
V newValue ;
2194
2194
@@ -2229,33 +2229,33 @@ V compute(K key, int hash, BiFunction<? super K, ? super V, ? extends V> functio
2229
2229
2230
2230
// note valueReference can be an existing value or even itself another loading value if
2231
2231
// the value for the key is already being computed.
2232
- loadingValueReference = new LoadingValueReference <>(valueReference );
2232
+ computingValueReference = new ComputingValueReference <>(valueReference );
2233
2233
2234
2234
if (e == null ) {
2235
2235
createNewEntry = true ;
2236
2236
e = newEntry (key , hash , first );
2237
- e .setValueReference (loadingValueReference );
2237
+ e .setValueReference (computingValueReference );
2238
2238
table .set (index , e );
2239
2239
} else {
2240
- e .setValueReference (loadingValueReference );
2240
+ e .setValueReference (computingValueReference );
2241
2241
}
2242
2242
2243
- newValue = loadingValueReference .compute (key , function );
2243
+ newValue = computingValueReference .compute (key , function );
2244
2244
if (newValue != null ) {
2245
2245
if (valueReference != null && newValue == valueReference .get ()) {
2246
- loadingValueReference .set (newValue );
2246
+ computingValueReference .set (newValue );
2247
2247
e .setValueReference (valueReference );
2248
2248
recordWrite (e , 0 , now ); // no change in weight
2249
2249
return newValue ;
2250
2250
}
2251
2251
try {
2252
2252
return getAndRecordStats (
2253
- key , hash , loadingValueReference , Futures .immediateFuture (newValue ));
2253
+ key , hash , computingValueReference , Futures .immediateFuture (newValue ));
2254
2254
} catch (ExecutionException exception ) {
2255
2255
throw new AssertionError ("impossible; Futures.immediateFuture can't throw" );
2256
2256
}
2257
- } else if (createNewEntry ) {
2258
- removeLoadingValue (key , hash , loadingValueReference );
2257
+ } else if (createNewEntry || valueReference . isLoading () ) {
2258
+ removeLoadingValue (key , hash , computingValueReference );
2259
2259
return null ;
2260
2260
} else {
2261
2261
removeEntry (e , hash , RemovalCause .EXPLICIT );
@@ -3603,6 +3603,17 @@ public ValueReference<K, V> copyFor(
3603
3603
}
3604
3604
}
3605
3605
3606
+ static class ComputingValueReference <K , V > extends LoadingValueReference <K , V > {
3607
+ ComputingValueReference (ValueReference <K , V > oldValue ) {
3608
+ super (oldValue );
3609
+ }
3610
+
3611
+ @ Override
3612
+ public boolean isLoading () {
3613
+ return false ;
3614
+ }
3615
+ }
3616
+
3606
3617
// Queues
3607
3618
3608
3619
/**
@@ -3927,7 +3938,7 @@ long longSize() {
3927
3938
Segment <K , V >[] segments = this .segments ;
3928
3939
long sum = 0 ;
3929
3940
for (int i = 0 ; i < segments .length ; ++i ) {
3930
- sum += Math . max ( 0 , segments [i ].count ); // see https://github.com/google/guava/issues/2108
3941
+ sum += segments [i ].count ;
3931
3942
}
3932
3943
return sum ;
3933
3944
}
0 commit comments