ifndef SymbolAsString sclass symbol_Tester { Symbol symbol; *() {} *(Symbol *symbol) {} public int hashCode() { ret symbol.text.hashCode(); } public bool equals(O o) { if (!o instanceof symbol_Tester) false; ret eq(symbol.text, o/symbol_Tester.symbol.text); } } static WeakHashMap symbol_map = unsyncedWeakHashMap(); static WeakHashMap masterSymbol_map = unsyncedWeakHashMap(); endifndef static Symbol symbol(S s) { ifdef SymbolAsString ret s; endifdef ifndef SymbolAsString if (s == null) null; synchronized(symbol_map) { // This is a trick that works because of how WeakHashMap compares keys. symbol_Tester tester = symbol_Tester(new MasterSymbol(s, true)); O e = call(symbol_map, 'getEntry, tester); symbol_Tester sym = e == null ? null : ((WeakReference) e).get(); if (sym == null) { O e = call(masterSymbol_map, 'getEntry, tester.symbol.master); MasterSymbol existingMaster = e == null ? null : ((WeakReference) e).get(); if (existingMaster != null) tester.symbol.master = existingMaster; else masterSymbol_map.put(tester.symbol.master, true); symbol_map.put(sym = tester, true); } ret sym.symbol; } endifndef } static Symbol symbol(CharSequence s) { if (s == null) null; ifdef SymbolAsString ret str(s); endifdef ifndef SymbolAsString if (s instanceof Symbol) ret (Symbol) s; if (s instanceof S) ret symbol((S) s); ret symbol(str(s)); endifndef }