GH-96458: Statically initialize utf8 representation of static strings (#96481)

This commit is contained in:
Kumar Aditya 2022-09-03 12:13:08 +05:30 committed by GitHub
parent 16c6759b37
commit 6dab8c95bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 139 additions and 165 deletions

View file

@ -195,7 +195,6 @@ class Printer:
else:
self.write("PyCompactUnicodeObject _compact;")
self.write(f"{datatype} _data[{len(s)+1}];")
self.deallocs.append(f"_PyStaticUnicode_Dealloc((PyObject *)&{name});")
with self.block(f"{name} =", ";"):
if ascii:
with self.block("._ascii =", ","):
@ -218,6 +217,9 @@ class Printer:
self.write(f".kind = {kind},")
self.write(".compact = 1,")
self.write(".ascii = 0,")
utf8 = s.encode('utf-8')
self.write(f'.utf8 = {make_string_literal(utf8)},')
self.write(f'.utf8_length = {len(utf8)},')
with self.block(f"._data =", ","):
for i in range(0, len(s), 16):
data = s[i:i+16]