GH-90699: Intern statically allocated strings (GH-93597)

This is similar to how strings are interned for deepfreeze.
This commit is contained in:
Kumar Aditya 2022-07-08 23:17:37 +05:30 committed by GitHub
parent be862b4e55
commit 9dff9f4814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 628 additions and 4 deletions

View file

@ -52,6 +52,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "pycore_pathconfig.h" // _Py_DumpPathConfig()
#include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_runtime_init.h" // _PyUnicode_InitStaticStrings()
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
#include "pycore_unicodeobject.h" // struct _Py_unicode_state
#include "stringlib/eq.h" // unicode_eq()
@ -14576,6 +14577,14 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp)
return _PyStatus_OK();
}
/* Intern statically allocated string identifiers and deepfreeze strings.
* This must be done before any module initialization so that statically
* allocated string identifiers are used instead of heap allocated strings.
* Deepfreeze uses the interned identifiers if present to save space
* else generates them and they are interned to speed up dict lookups.
*/
_PyUnicode_InitStaticStrings();
#ifdef Py_DEBUG
assert(_PyUnicode_CheckConsistency(&_Py_STR(empty), 1));