]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46471: Use single byte singletons (GH-30781)
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Sun, 23 Jan 2022 17:45:39 +0000 (23:15 +0530)
committerGitHub <noreply@github.com>
Sun, 23 Jan 2022 17:45:39 +0000 (09:45 -0800)
Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst [new file with mode: 0644]
Tools/scripts/deepfreeze.py

diff --git a/Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst b/Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst
new file mode 100644 (file)
index 0000000..ca8f728
--- /dev/null
@@ -0,0 +1 @@
+Use global singletons for single byte bytes objects in deepfreeze.
\ No newline at end of file
index a7546a8c6075153461abe7db30ee65a125a5f4ce..a1ef85ea891a27d2e66364787f3a29f828cc4784 100644 (file)
@@ -150,6 +150,8 @@ class Printer:
     def generate_bytes(self, name: str, b: bytes) -> str:
         if b == b"":
             return "(PyObject *)&_Py_SINGLETON(bytes_empty)"
+        if len(b) == 1:
+            return f"(PyObject *)&_Py_SINGLETON(bytes_characters[{b[0]}])"
         self.write("static")
         with self.indent():
             with self.block("struct"):