String Interning
See [hstr
][] for more details.
SWC interns strings if it's not too short nor too long. This is useful for reducing memory usage and improving performance because SWC is a sort of compiler. Many variables share the same string, and we have to perform lots of hash operations on them.
It does not intern too short strings because we can avoid allocations for them. It does not intern too long strings because it's not worth it. Typically, long strings are not same to each other.
While interning strings, SWC calculates the hash of the string.
It makes hash()
O(1)
. eq
becomes much faster although it's not strictly O(1)
.