@@ -38,7 +38,7 @@ public class SymbolTable {
38
38
// However, this doesn't matter as the cache entries will be re-created when used.
39
39
private final WeakValueCache <String , RubySymbol > stringToSymbolCache = new WeakValueCache <>();
40
40
41
- // Weak map of RopeKey to Symbol to keep Symbols unique.
41
+ // Weak map of RopeWithEncoding to Symbol to keep Symbols unique.
42
42
// As long as the Symbol is referenced, the entry will stay in the symbolMap.
43
43
private final WeakValueCache <RopeWithEncoding , RubySymbol > symbolMap = new WeakValueCache <>();
44
44
@@ -50,17 +50,19 @@ public SymbolTable(RopeCache ropeCache, CoreSymbols coreSymbols) {
50
50
private void addCoreSymbols (CoreSymbols coreSymbols ) {
51
51
for (RubySymbol symbol : coreSymbols .CORE_SYMBOLS ) {
52
52
final Rope rope = symbol .getRope ();
53
- assert rope == normalizeRopeForLookup (rope , symbol .encoding ).getRope ();
53
+ final RopeWithEncoding ropeWithEncoding = normalizeRopeForLookup (rope , symbol .encoding );
54
+ assert rope == ropeWithEncoding .getRope ();
54
55
assert rope == ropeCache .getRope (rope );
55
56
56
- final RopeWithEncoding ropeWithEncoding = new RopeWithEncoding (rope , symbol .encoding );
57
57
final RubySymbol existing = symbolMap .put (ropeWithEncoding , symbol );
58
58
if (existing != null ) {
59
59
throw new AssertionError ("Duplicate Symbol in SymbolTable: " + existing );
60
60
}
61
61
62
62
final RubySymbol old = stringToSymbolCache .put (symbol .getString (), symbol );
63
- assert old == null || new RopeWithEncoding (old .getRope (), old .encoding ).equals (ropeWithEncoding );
63
+ if (old != null ) {
64
+ throw new AssertionError ("Duplicate Symbol in SymbolTable: " + old );
65
+ }
64
66
}
65
67
}
66
68
@@ -82,26 +84,26 @@ public RubySymbol getSymbol(String string) {
82
84
}
83
85
symbol = getSymbol (rope , encoding );
84
86
85
- // Add it to the direct j.l.String to Symbol cache
86
-
87
+ // Add it to the direct java.lang.String to Symbol cache
87
88
stringToSymbolCache .addInCacheIfAbsent (string , symbol );
88
89
89
90
return symbol ;
90
91
}
91
92
92
93
@ TruffleBoundary
93
94
public RubySymbol getSymbol (Rope rope , RubyEncoding encoding ) {
94
- final RopeWithEncoding normalizedRope = normalizeRopeForLookup (rope , encoding );
95
- final RubySymbol symbol = symbolMap .get (normalizedRope );
95
+ final RopeWithEncoding ropeEncodingForLookup = normalizeRopeForLookup (rope , encoding );
96
+ final RubySymbol symbol = symbolMap .get (ropeEncodingForLookup );
96
97
if (symbol != null ) {
97
98
return symbol ;
98
99
}
99
100
100
- final LeafRope cachedRope = ropeCache .getRope (normalizedRope .getRope ());
101
- final RubySymbol newSymbol = createSymbol (cachedRope , normalizedRope .getEncoding ());
102
- // Use a RopeKey with the cached Rope in symbolMap, since the Symbol refers to it and so we
101
+ final LeafRope cachedRope = ropeCache .getRope (ropeEncodingForLookup .getRope ());
102
+ final RubyEncoding symbolEncoding = ropeEncodingForLookup .getEncoding ();
103
+ final RubySymbol newSymbol = createSymbol (cachedRope , symbolEncoding );
104
+ // Use a RopeWithEncoding with the cached Rope in symbolMap, since the Symbol refers to it and so we
103
105
// do not keep rope alive unnecessarily.
104
- return symbolMap .addInCacheIfAbsent (new RopeWithEncoding (cachedRope , normalizedRope . getEncoding () ), newSymbol );
106
+ return symbolMap .addInCacheIfAbsent (new RopeWithEncoding (cachedRope , symbolEncoding ), newSymbol );
105
107
}
106
108
107
109
@ TruffleBoundary
0 commit comments