From ca78130d7eb5265759697639e42487ec6d0a4caf Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Sun, 23 Jan 2022 23:15:39 +0530 Subject: bpo-46471: Use single byte singletons (GH-30781) --- Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst | 1 + Tools/scripts/deepfreeze.py | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2022-01-22-11-06-23.bpo-46471.03snrE.rst 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 0000000..ca8f728 --- /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 a7546a8..a1ef85e 100644 --- a/Tools/scripts/deepfreeze.py +++ b/Tools/scripts/deepfreeze.py @@ -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"): -- cgit v0.12