Skip to content

Commit

Permalink
Fix concurrent modification
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Feb 25, 2025
1 parent 64db6b7 commit 63e58b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@ protected ConstraintTypeCache(Function<C, T> createFn) {
}

T get(C constraint) {
return cache.computeIfAbsent(constraintInterner.intern(constraint), createFn);
var cached = cache.get(constraint);
if (cached != null) {
return cached;
}
cached = createFn.apply(constraint);
cache.put(constraint, cached);
return cached;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ private static TypeCheckFlyweight getUnnamed(int typeId) {
}

private static TypeCheckFlyweight getNamed(int typeId) {
return namedTypeCache.computeIfAbsent(typeId, TypeCheckFlyweight::new);
var cached = namedTypeCache.get(typeId);
if (cached != null) {
return cached;
}
cached = new TypeCheckFlyweight(typeId);
namedTypeCache.put(typeId, cached);
return cached;
}

private static TypeCheckFlyweight getReserved(int typeId) {
Expand All @@ -174,4 +180,4 @@ public TypeCheckFlyweight(Integer constraintId) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ private TypeCheckCacheFlyweight<E> getUnnamed(int typeId) {
}

private TypeCheckCacheFlyweight<E> getNamed(int typeId) {
return namedTypeCache.computeIfAbsent(typeId, createFn::apply);
var cached = namedTypeCache.get(typeId);
if (cached != null) {
return cached;
}
cached = createFn.apply(typeId);
namedTypeCache.put(typeId, cached);
return cached;
}
}
}

0 comments on commit 63e58b9

Please sign in to comment.