Skip to content

Commit

Permalink
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -33,7 +33,8 @@

public class SymbolTable {

private final DynamicObjectFactory symbolFactory;
private final RubyContext context;
private DynamicObjectFactory symbolFactory;

private final ReadWriteLock lock = new ReentrantReadWriteLock();

@@ -46,7 +47,7 @@ public class SymbolTable {
private final Map<SymbolEquality, Reference<DynamicObject>> symbolSet = new WeakHashMap<>();

public SymbolTable(RubyContext context) {
this.symbolFactory = Layouts.CLASS.getInstanceFactory(context.getCoreLibrary().getSymbolClass());
this.context = context;
}

@TruffleBoundary
@@ -129,7 +130,7 @@ private DynamicObject createSymbol(Rope rope) {
// Symbol has to have reference to its SymbolEquality otherwise it would be GCed.
final SymbolEquality equalityWrapper = new SymbolEquality();
final DynamicObject symbol = Layouts.SYMBOL.createSymbol(
symbolFactory,
getSymbolFactory(),
string,
rope,
string.hashCode(),
@@ -139,6 +140,13 @@ private DynamicObject createSymbol(Rope rope) {
return symbol;
}

private DynamicObjectFactory getSymbolFactory() {
if (symbolFactory == null) {
symbolFactory = Layouts.CLASS.getInstanceFactory(context.getCoreLibrary().getSymbolClass());
}
return symbolFactory;
}

private <K, V> V readRef(Map<K, Reference<V>> map, K key) {
Reference<V> reference = map.get(key);
return reference == null ? null : reference.get();

0 comments on commit 45885c9

Please sign in to comment.