[Python-checkins] bpo-46471: Use single byte singletons (GH-30781)

gvanrossum webhook-mailer at python.org
Sun Jan 23 12:46:04 EST 2022


https://github.com/python/cpython/commit/ca78130d7eb5265759697639e42487ec6d0a4caf
commit: ca78130d7eb5265759697639e42487ec6d0a4caf
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-01-23T09:45:39-08:00
summary:

bpo-46471: Use single byte singletons (GH-30781)

files:
A Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst
M 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
index 0000000000000..ca8f72868e69e
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst
@@ -0,0 +1 @@
+Use global singletons for single byte bytes objects in deepfreeze.
\ No newline at end of file
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index a7546a8c60751..a1ef85ea891a2 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -150,6 +150,8 @@ def field(self, obj: object, name: str) -> None:
     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"):



More information about the Python-checkins mailing list