Skip to content

Commit

Permalink
Ensure fstring dedup locks in the first string created.
Browse files Browse the repository at this point in the history
headius committed Oct 10, 2017

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent 7f2d94a commit 4cf3989
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -4642,7 +4642,7 @@ public RubyString freezeAndDedupString(RubyString string) {
if (dedupedRef == null || (deduped = dedupedRef.get()) == null) {
deduped = string.strDup(this);
deduped.setFrozen(true);
dedupMap.put(string, new WeakReference<RubyString>(deduped));
dedupMap.putIfAbsent(string, new WeakReference<RubyString>(deduped));
} else if (deduped.getEncoding() != string.getEncoding()) {
// if encodings don't match, new string loses; can't dedup
deduped = string.strDup(this);
@@ -5149,7 +5149,7 @@ public void addToObjectSpace(boolean useObjectSpace, IRubyObject object) {
*
* Access must be synchronized.
*/
private Map<RubyString, WeakReference<RubyString>> dedupMap = Collections.synchronizedMap(new WeakHashMap<RubyString, WeakReference<RubyString>>());
private ConcurrentHashMap<RubyString, WeakReference<RubyString>> dedupMap = new ConcurrentHashMap<>();

private static final AtomicInteger RUNTIME_NUMBER = new AtomicInteger(0);
private final int runtimeNumber = RUNTIME_NUMBER.getAndIncrement();

0 comments on commit 4cf3989

Please sign in to comment.