Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
deepfreeze use preallocated small ints
  • Loading branch information
kumaraditya303 committed Jan 20, 2022
commit 7fb3f2295534a3cc0ce45779fc8f070e506e554d
3 changes: 3 additions & 0 deletions Tools/scripts/deepfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(self, file: TextIO):
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
Expand Down Expand Up @@ -313,6 +314,8 @@ def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None:
self.write(f".ob_digit = {{ {ds} }},")

def generate_int(self, name: str, i: int) -> str:
if -5 <= i <= 256:
Comment thread
kumaraditya303 marked this conversation as resolved.
return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]"
if abs(i) < 2**15:
self._generate_int_for_bits(name, i, 2**15)
else:
Expand Down