gh-103875: Use ascii and latin1 singletons in deepfreeze (#103876)

This commit is contained in:
Yichen Yan 2023-04-26 19:45:58 +08:00 committed by GitHub
parent 438b811761
commit 214e5684c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -175,6 +175,12 @@ class Printer:
return f"&_Py_STR({strings[s]})"
if s in identifiers:
return f"&_Py_ID({s})"
if len(s) == 1:
c = ord(s)
if c < 128:
return f"(PyObject *)&_Py_SINGLETON(strings).ascii[{c}]"
elif c < 256:
return f"(PyObject *)&_Py_SINGLETON(strings).latin1[{c - 128}]"
if re.match(r'\A[A-Za-z0-9_]+\Z', s):
name = f"const_str_{s}"
kind, ascii = analyze_character_width(s)