Warning: session_start(): open(/var/lib/php/sessions/sess_suj2paqvuv7jfb3eq1nu0tevs3, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
sclass Symbol {
S text;
*() {}
*(S *text, bool dummy) {} // weird signature to prevent accidental calling
public int hashCode() { ret main.hashCode(text); }
toString { ret text; }
public bool equals(O o) {
ret this == o;
}
}
sclass SymbolTester {
S text;
*() {}
*(S *text) {}
public int hashCode() { ret main.hashCode(text); }
public bool equals(O o) {
ret o instanceof Symbol && eq(text, o/Symbol.text);
}
}
static new WeakHashMap symbolMap;
static Symbol symbol(S s) {
if (s == null) null;
synchronized(symbolMap) {
// This is a trick that works because of how WeakHashMap compares keys.
SymbolTester test = new(s);
//WeakHashMap2.Entry e = symbolMap.getEntry(test);
//Symbol sym = e == null ? null : e.get();
O e = call(symbolMap, 'getEntry, test);
Symbol sym = e == null ? null : ((WeakReference) e).get();
if (sym == null)
symbolMap.put(sym = Symbol(s, false), Bool.TRUE);
ret sym;
}
}
p {
S s1 = "a", s2 = lower("A");
assertNotIdentical(s1, s2); // Now more clearly showing the improvement
Symbol a = symbol(s1);
Symbol a2 = symbol(s2);
assertEquals("a", str(a));
assertEquals("a", str(a2));
assertIdentical(a, a2);
Symbol b = symbol("b");
assertEquals("b", str(b));
print("OK");
}