Skip to content

Commit 214e568

Browse files
authored
gh-103875: Use ascii and latin1 singletons in deepfreeze (#103876)
1 parent 438b811 commit 214e568

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Tools/build/deepfreeze.py

+6
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ def generate_unicode(self, name: str, s: str) -> str:
175175
return f"&_Py_STR({strings[s]})"
176176
if s in identifiers:
177177
return f"&_Py_ID({s})"
178+
if len(s) == 1:
179+
c = ord(s)
180+
if c < 128:
181+
return f"(PyObject *)&_Py_SINGLETON(strings).ascii[{c}]"
182+
elif c < 256:
183+
return f"(PyObject *)&_Py_SINGLETON(strings).latin1[{c - 128}]"
178184
if re.match(r'\A[A-Za-z0-9_]+\Z', s):
179185
name = f"const_str_{s}"
180186
kind, ascii = analyze_character_width(s)

0 commit comments

Comments
 (0)