Skip to content

Commit fc97cd8

Browse files
committedJan 22, 2018
Revert "Avoid race when deduplicating frozen strings. Fixes #4970."
This reverts commit 23783ce.
1 parent 4b6eeb6 commit fc97cd8

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed
 

‎core/src/main/java/org/jruby/Ruby.java

+1-33
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@
195195
import java.util.concurrent.TimeUnit;
196196
import java.util.concurrent.atomic.AtomicInteger;
197197
import java.util.concurrent.atomic.AtomicLong;
198-
import java.util.function.BiFunction;
199-
import java.util.function.Function;
200198
import java.util.regex.Pattern;
201199

202200
import static java.lang.invoke.MethodHandles.explicitCastArguments;
@@ -4579,41 +4577,11 @@ public RubyString freezeAndDedupString(RubyString string) {
45794577
RubyString deduped;
45804578

45814579
if (dedupedRef == null || (deduped = dedupedRef.get()) == null) {
4582-
// Never use value as key
45834580
deduped = string.strDup(this);
45844581
deduped.setFrozen(true);
4585-
4586-
final WeakReference<RubyString> weakref = new WeakReference<>(deduped);
4587-
4588-
// try to insert new
4589-
dedupedRef = dedupMap.computeIfAbsent(string, new Function<RubyString, WeakReference<RubyString>>() {
4590-
@Override
4591-
public WeakReference<RubyString> apply(RubyString key) {
4592-
return weakref;
4593-
}
4594-
});
4595-
if (dedupedRef == null) return deduped;
4596-
4597-
// entry exists, return result if not vacated
4598-
RubyString unduped = dedupedRef.get();
4599-
if (unduped != null) return unduped;
4600-
4601-
// ref is there but vacated, try to replace it until we have a result
4602-
while (true) {
4603-
dedupedRef = dedupMap.computeIfPresent(string, new BiFunction<RubyString, WeakReference<RubyString>, WeakReference<RubyString>>() {
4604-
@Override
4605-
public WeakReference<RubyString> apply(RubyString key, WeakReference<RubyString> old) {
4606-
return old.get() == null ? weakref : old;
4607-
}
4608-
});
4609-
4610-
// return result if not vacated
4611-
unduped = dedupedRef.get();
4612-
if (unduped != null) return unduped;
4613-
}
4582+
dedupMap.put(string, new WeakReference<RubyString>(deduped));
46144583
} else if (deduped.getEncoding() != string.getEncoding()) {
46154584
// if encodings don't match, new string loses; can't dedup
4616-
// FIXME: This may never happen, if we are properly considering encoding in RubyString.hashCode
46174585
deduped = string.strDup(this);
46184586
deduped.setFrozen(true);
46194587
}

0 commit comments

Comments
 (0)