ifndef SymbolAsString static WeakHasherMap symbol_map = new WeakHasherMap(new Hasher() { public int hashCode(Symbol symbol) { ret symbol.text.hashCode(); } public bool equals(Symbol a, Symbol b) { if (a == null) ret b == null; ret b != null && eq(a.text, b.text); } }); static WeakHasherMap masterSymbol_map = new WeakHasherMap(new Hasher() { public int hashCode(MasterSymbol symbol) { ret symbol.lowerCaseHash(); } public bool equals(MasterSymbol a, MasterSymbol b) { if (a == null) ret b == null; ret b != null && eq(a.lowerCase(), b.lowerCase()); } }); endifndef static Symbol symbol(S s) { ifdef SymbolAsString ret s; endifdef ifndef SymbolAsString if (s == null) null; synchronized(symbol_map) { MasterSymbol master = new MasterSymbol(s, true); MasterSymbol existingMaster = masterSymbol_map.findKey(master); if (existingMaster == null) masterSymbol_map.put(existingMaster = master, true); ifdef symbol_debug if (eqic(s, "Java")) print("existing master for " + s + ": " + existingMaster); endifdef // directly return master if exact match bool isEq = eq(s, existingMaster.text); if (isEq) ret existingMaster; // second lookup after master found Symbol symbol = new Symbol(s, existingMaster); Symbol existingSymbol = symbol_map.findKey(symbol); if (existingSymbol == null) symbol_map.put(existingSymbol = symbol, true); ifdef symbol_debug if (eqic(s, "Java")) print("Symbol for " + s + ": " + symbolToStringFull(existingSymbol); endifdef ret existingSymbol; } 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 } static Symbol symbol(O o) { ret symbol((CharSequence) o); }