mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-106931: Intern Statically Allocated Strings Globally (gh-107272)
We tried this before with a dict and for all interned strings. That ran into problems due to interpreter isolation. However, exclusively using a per-interpreter cache caused some inconsistency that can eliminate the benefit of interning. Here we circle back to using a global cache, but only for statically allocated strings. We also use a more-basic _Py_hashtable_t for that global cache instead of a dict. Ideally we would only have the global cache, but the optional isolation of each interpreter's allocator means that a non-static string object must not outlive its interpreter. Thus we would have to store a copy of each such interned string in the global cache, tied to the main interpreter.
This commit is contained in:
parent
4f67921ad2
commit
b72947a8d2
10 changed files with 123 additions and 4 deletions
|
@ -129,6 +129,13 @@ _Py_hashtable_size(const _Py_hashtable_t *ht)
|
|||
}
|
||||
|
||||
|
||||
size_t
|
||||
_Py_hashtable_len(const _Py_hashtable_t *ht)
|
||||
{
|
||||
return ht->nentries;
|
||||
}
|
||||
|
||||
|
||||
_Py_hashtable_entry_t *
|
||||
_Py_hashtable_get_entry_generic(_Py_hashtable_t *ht, const void *key)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue