Skip to content

Commit ca78130

Browse files
bpo-46471: Use single byte singletons (GH-30781)
1 parent 691506f commit ca78130

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use global singletons for single byte bytes objects in deepfreeze.

Tools/scripts/deepfreeze.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def field(self, obj: object, name: str) -> None:
150150
def generate_bytes(self, name: str, b: bytes) -> str:
151151
if b == b"":
152152
return "(PyObject *)&_Py_SINGLETON(bytes_empty)"
153+
if len(b) == 1:
154+
return f"(PyObject *)&_Py_SINGLETON(bytes_characters[{b[0]}])"
153155
self.write("static")
154156
with self.indent():
155157
with self.block("struct"):

0 commit comments

Comments
 (0)