Skip to content

Commit

Permalink
Do not use HashMap.computeIfAbsent
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMil committed Nov 7, 2024
1 parent 9be2315 commit f40c5ce
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/soot/ArrayTypeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ArrayType apply(Pair<Type, Integer> t) {
if (ret == null) {
int n = orgDimensions - numDimensions + 1;
if (n != orgDimensions) {
ret = cache.computeIfAbsent(new Pair<>(baseType, n), mapping);
ret = getArrayType(baseType, n);
} else {
ret = new ArrayType(baseType, n);
}
Expand Down Expand Up @@ -82,8 +82,13 @@ public ArrayTypeCache(Global g) {
//method does not allow the update of other keys in while a value is computed.
public synchronized ArrayType getArrayType(Type baseType, int numDimensions) {
Pair<Type, Integer> pairSearch = new Pair<>(baseType, numDimensions);
ArrayType res = cache.get(pairSearch);
if (res == null) {
res = mapping.apply(pairSearch);
cache.put(pairSearch, res);
}

return cache.computeIfAbsent(pairSearch, mapping);
return res;

}

Expand Down

0 comments on commit f40c5ce

Please sign in to comment.