Strings are immutable, but from the code it doesn’t look like they are pooled by default (there’s StringPool
). Why? I would guess that the improvement in cache locality would offset any speed hit. It looks like the compiler tries to pool literals.
a = "foo"
b = "fox".sub("x", "o")
p pointerof(a).value.as(Pointer(UInt8))
p pointerof(b).value.as(Pointer(UInt8))
p a == b
gets:
"Pointer(String)@0x7ffdacedce00"
"Pointer(String)@0x7ffdacedcdf8"
true