mirror of
https://github.com/python/cpython.git
synced 2025-07-25 12:14:38 +00:00
GH-96458: Statically initialize utf8 representation of static strings (#96481)
This commit is contained in:
parent
16c6759b37
commit
6dab8c95bd
6 changed files with 139 additions and 165 deletions
|
@ -287,7 +287,11 @@ def generate_runtime_init(identifiers, strings):
|
|||
immortal_objects.append(f'(PyObject *)&_Py_SINGLETON(strings).ascii[{i}]')
|
||||
with printer.block('.latin1 =', ','):
|
||||
for i in range(128, 256):
|
||||
printer.write(f'_PyUnicode_LATIN1_INIT("\\x{i:02x}"),')
|
||||
utf8 = ['"']
|
||||
for c in chr(i).encode('utf-8'):
|
||||
utf8.append(f"\\x{c:02x}")
|
||||
utf8.append('"')
|
||||
printer.write(f'_PyUnicode_LATIN1_INIT("\\x{i:02x}", {"".join(utf8)}),')
|
||||
immortal_objects.append(f'(PyObject *)&_Py_SINGLETON(strings).latin1[{i} - 128]')
|
||||
printer.write('')
|
||||
with printer.block('.tuple_empty =', ','):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue