4 ms·
I use something like: @functools.cache def dedup(s): return sys.intern(s)
by ciupicri 5y ago
I use something like:
@functools.cache
def dedup(s):
return sys.intern(s)
- twic 5y agoIsn't sys.intern a cache itself? What does adding another layer of cacheing on top add?
- ciupicri 5y agoYou're right, PyUnicode_InternInPlace (which is called by sys.intern) already caches results using a regular Python dictionary, so @functools.cache wouldn't add any value. It happened a long time ago, but I think I misread something about sys.intern not being able to handle lots and lots of strings, so I added an extra layer of caching, but it looks like it's not needed anymore. [1]: https://github.com/python/cpython/blob/3.10/Objects/unicodeobject.c#L15794 https://github.com/python/cpython/blob/3.10/Objects/unicodeo...