|
195 | 195 | import java.util.concurrent.TimeUnit;
|
196 | 196 | import java.util.concurrent.atomic.AtomicInteger;
|
197 | 197 | import java.util.concurrent.atomic.AtomicLong;
|
198 |
| -import java.util.function.BiFunction; |
199 |
| -import java.util.function.Function; |
200 | 198 | import java.util.regex.Pattern;
|
201 | 199 |
|
202 | 200 | import static java.lang.invoke.MethodHandles.explicitCastArguments;
|
@@ -4579,41 +4577,11 @@ public RubyString freezeAndDedupString(RubyString string) {
|
4579 | 4577 | RubyString deduped;
|
4580 | 4578 |
|
4581 | 4579 | if (dedupedRef == null || (deduped = dedupedRef.get()) == null) {
|
4582 |
| - // Never use value as key |
4583 | 4580 | deduped = string.strDup(this);
|
4584 | 4581 | 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)); |
4614 | 4583 | } else if (deduped.getEncoding() != string.getEncoding()) {
|
4615 | 4584 | // 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 |
4617 | 4585 | deduped = string.strDup(this);
|
4618 | 4586 | deduped.setFrozen(true);
|
4619 | 4587 | }
|
|
0 commit comments