mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-46443: deepfreeze: use small ints and singleton zero bytes (GH-30715)
This commit is contained in:
parent
263c0dd160
commit
194ecc6d44
2 changed files with 6 additions and 0 deletions
|
@ -0,0 +1 @@
|
||||||
|
Deepfreeze now uses cached small integers as it saves some space for common small integers.
|
|
@ -113,6 +113,7 @@ class Printer:
|
||||||
self.write('#include "Python.h"')
|
self.write('#include "Python.h"')
|
||||||
self.write('#include "internal/pycore_gc.h"')
|
self.write('#include "internal/pycore_gc.h"')
|
||||||
self.write('#include "internal/pycore_code.h"')
|
self.write('#include "internal/pycore_code.h"')
|
||||||
|
self.write('#include "internal/pycore_long.h"')
|
||||||
self.write("")
|
self.write("")
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
|
@ -148,6 +149,8 @@ class Printer:
|
||||||
self.write(f".{name} = {getattr(obj, name)},")
|
self.write(f".{name} = {getattr(obj, name)},")
|
||||||
|
|
||||||
def generate_bytes(self, name: str, b: bytes) -> str:
|
def generate_bytes(self, name: str, b: bytes) -> str:
|
||||||
|
if b == b"":
|
||||||
|
return "(PyObject *)&_Py_SINGLETON(bytes_empty)"
|
||||||
self.write("static")
|
self.write("static")
|
||||||
with self.indent():
|
with self.indent():
|
||||||
with self.block("struct"):
|
with self.block("struct"):
|
||||||
|
@ -313,6 +316,8 @@ class Printer:
|
||||||
self.write(f".ob_digit = {{ {ds} }},")
|
self.write(f".ob_digit = {{ {ds} }},")
|
||||||
|
|
||||||
def generate_int(self, name: str, i: int) -> str:
|
def generate_int(self, name: str, i: int) -> str:
|
||||||
|
if -5 <= i <= 256:
|
||||||
|
return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]"
|
||||||
if abs(i) < 2**15:
|
if abs(i) < 2**15:
|
||||||
self._generate_int_for_bits(name, i, 2**15)
|
self._generate_int_for_bits(name, i, 2**15)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue