A small library for best-effort interning and memoization of arbitrary types, with specializations for string
, []byte
, and []rune
.
Compared to the josharian/intern
upstream this fork:
- supports also
[]rune
in addition tostring
and[]byte
- makes use of generics (as such it requires Go >= 1.18)
- provides a generic
Map[K, V]
interner that allows to intern/memoize custom types (seeExampleMap
) - optionally provide a
unsafe
-based implementation that is ~25% faster than the regular one and that it is more stable (less likely to cause OOM errors under pathological usage patterns): it can be enabled with theintern_unsafe
build tag
For a blog post introducing string interning, see: https://commaok.xyz/post/intern-strings/
License: MIT