From 4ae74ca67b6fa3e2eabe76a04857393a7ca437ad Mon Sep 17 00:00:00 2001 From: Yichen Yan Date: Wed, 26 Apr 2023 18:40:21 +0800 Subject: [PATCH] Use char and latin1 singletons in deepfreeze. --- Tools/build/deepfreeze.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tools/build/deepfreeze.py b/Tools/build/deepfreeze.py index 5cfef5c572c4ae..b084d3e457f782 100644 --- a/Tools/build/deepfreeze.py +++ b/Tools/build/deepfreeze.py @@ -175,6 +175,12 @@ def generate_unicode(self, name: str, s: str) -> str: 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)