Skip to content

Commit b2e0bed

Browse files
committed
Lint: Prefer getOrCompute() to computeIfAbsent()
1 parent 3a0c9c5 commit b2e0bed

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/main/java/org/truffleruby/collections/ConcurrentOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public abstract class ConcurrentOperations {
1919
* Replaces {@link ConcurrentHashMap#computeIfAbsent(Object, Function)} as it does not scale.
2020
* The JDK method takes a monitor for every access if the key is present.
2121
* See https://bugs.openjdk.java.net/browse/JDK-8161372 which only fixes it in Java 9
22-
* if they are no collisions in the bucket.
22+
* if there are no collisions in the bucket.
2323
* This method might execute the function multiple times, in contrast to computeIfAbsent().
2424
*/
2525
public static <K, V> V getOrCompute(Map<K, V> map, K key, Function<? super K, ? extends V> compute) {

src/main/java/org/truffleruby/language/loader/FeatureLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.truffleruby.RubyLanguage;
2626
import org.truffleruby.cext.WrapNodeGen;
2727
import org.truffleruby.cext.WrapNode;
28+
import org.truffleruby.collections.ConcurrentOperations;
2829
import org.truffleruby.core.array.ArrayOperations;
2930
import org.truffleruby.core.encoding.EncodingManager;
3031
import org.truffleruby.core.support.IONodes.GetThreadBufferNode;
@@ -85,7 +86,7 @@ public void addAutoload(RubyConstant autoloadConstant) {
8586

8687
registeredAutoloadsLock.lock();
8788
try {
88-
final Map<String, RubyConstant> constants = registeredAutoloads.computeIfAbsent(basename, k -> new HashMap<>());
89+
final Map<String, RubyConstant> constants = ConcurrentOperations.getOrCompute(registeredAutoloads, basename, k -> new HashMap<>());
8990
constants.put(StringOperations.getString(autoloadConstant.getAutoloadPath()), autoloadConstant);
9091
} finally {
9192
registeredAutoloadsLock.unlock();

0 commit comments

Comments
 (0)