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

This commit is contained in:
Kumar Aditya 2022-01-23 23:15:39 +05:30 committed by GitHub
parent 691506f4e9
commit ca78130d7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View file

@ -0,0 +1 @@
Use global singletons for single byte bytes objects in deepfreeze.

View file

@ -150,6 +150,8 @@ class Printer:
def generate_bytes(self, name: str, b: bytes) -> str: def generate_bytes(self, name: str, b: bytes) -> str:
if b == b"": if b == b"":
return "(PyObject *)&_Py_SINGLETON(bytes_empty)" return "(PyObject *)&_Py_SINGLETON(bytes_empty)"
if len(b) == 1:
return f"(PyObject *)&_Py_SINGLETON(bytes_characters[{b[0]}])"
self.write("static") self.write("static")
with self.indent(): with self.indent():
with self.block("struct"): with self.block("struct"):