summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-01-20 06:13:21 (GMT)
committerGitHub <noreply@github.com>2022-01-20 06:13:21 (GMT)
commit194ecc6d44adc1fb39a56ca696418368b69432ce (patch)
treedeb26d6a3be7f9c430b50874ef898ccdd5a9ba51 /Tools
parent263c0dd16017613c5ea2fbfc270be4de2b41b5ad (diff)
downloadcpython-194ecc6d44adc1fb39a56ca696418368b69432ce.zip
cpython-194ecc6d44adc1fb39a56ca696418368b69432ce.tar.gz
cpython-194ecc6d44adc1fb39a56ca696418368b69432ce.tar.bz2
bpo-46443: deepfreeze: use small ints and singleton zero bytes (GH-30715)
Diffstat (limited to 'Tools')
-rw-r--r--Tools/scripts/deepfreeze.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 002d680..49638b8 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -113,6 +113,7 @@ class Printer:
self.write('#include "Python.h"')
self.write('#include "internal/pycore_gc.h"')
self.write('#include "internal/pycore_code.h"')
+ self.write('#include "internal/pycore_long.h"')
self.write("")
@contextlib.contextmanager
@@ -148,6 +149,8 @@ class Printer:
self.write(f".{name} = {getattr(obj, name)},")
def generate_bytes(self, name: str, b: bytes) -> str:
+ if b == b"":
+ return "(PyObject *)&_Py_SINGLETON(bytes_empty)"
self.write("static")
with self.indent():
with self.block("struct"):
@@ -313,6 +316,8 @@ class Printer:
self.write(f".ob_digit = {{ {ds} }},")
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:
self._generate_int_for_bits(name, i, 2**15)
else: