]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103875: Use ascii and latin1 singletons in deepfreeze (#103876)
authorYichen Yan <oraluben@outlook.com>
Wed, 26 Apr 2023 11:45:58 +0000 (19:45 +0800)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2023 11:45:58 +0000 (11:45 +0000)
Tools/build/deepfreeze.py

index 5cfef5c572c4ae3a739bde94af15e9f836bae040..b084d3e457f7827899bb49b8b7629c114aa0142e 100644 (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)