Skip to content

Commit

Permalink
bpo-46765: Replace Locally Cached Strings with Statically Initialized…
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Feb 23, 2022
1 parent cff4d5c commit 1f45536
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 526 deletions.
32 changes: 32 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,26 @@ struct _Py_global_strings {
STRUCT_FOR_STR(anon_module, "<module>")
STRUCT_FOR_STR(anon_setcomp, "<setcomp>")
STRUCT_FOR_STR(anon_string, "<string>")
STRUCT_FOR_STR(anon_unknown, "<unknown>")
STRUCT_FOR_STR(close_br, "}")
STRUCT_FOR_STR(comma_sep, ", ")
STRUCT_FOR_STR(dbl_close_br, "}}")
STRUCT_FOR_STR(dbl_open_br, "{{")
STRUCT_FOR_STR(dbl_percent, "%%")
STRUCT_FOR_STR(dot, ".")
STRUCT_FOR_STR(dot_locals, ".<locals>")
STRUCT_FOR_STR(empty, "")
STRUCT_FOR_STR(list_err, "list index out of range")
STRUCT_FOR_STR(newline, "\n")
STRUCT_FOR_STR(open_br, "{")
STRUCT_FOR_STR(percent, "%")
} literals;

struct {
STRUCT_FOR_ID(False)
STRUCT_FOR_ID(Py_Repr)
STRUCT_FOR_ID(TextIOWrapper)
STRUCT_FOR_ID(True)
STRUCT_FOR_ID(WarningMessage)
STRUCT_FOR_ID(_)
STRUCT_FOR_ID(__IOBase_closed)
Expand Down Expand Up @@ -194,7 +203,9 @@ struct _Py_global_strings {
STRUCT_FOR_ID(__weakref__)
STRUCT_FOR_ID(__xor__)
STRUCT_FOR_ID(_abc_impl)
STRUCT_FOR_ID(_annotation)
STRUCT_FOR_ID(_blksize)
STRUCT_FOR_ID(_bootstrap)
STRUCT_FOR_ID(_dealloc_warn)
STRUCT_FOR_ID(_finalizing)
STRUCT_FOR_ID(_find_and_load)
Expand All @@ -216,46 +227,62 @@ struct _Py_global_strings {
STRUCT_FOR_ID(big)
STRUCT_FOR_ID(buffer)
STRUCT_FOR_ID(builtins)
STRUCT_FOR_ID(c_call)
STRUCT_FOR_ID(c_exception)
STRUCT_FOR_ID(c_return)
STRUCT_FOR_ID(call)
STRUCT_FOR_ID(clear)
STRUCT_FOR_ID(close)
STRUCT_FOR_ID(closed)
STRUCT_FOR_ID(code)
STRUCT_FOR_ID(copy)
STRUCT_FOR_ID(copyreg)
STRUCT_FOR_ID(decode)
STRUCT_FOR_ID(default)
STRUCT_FOR_ID(defaultaction)
STRUCT_FOR_ID(dictcomp)
STRUCT_FOR_ID(difference_update)
STRUCT_FOR_ID(dispatch_table)
STRUCT_FOR_ID(displayhook)
STRUCT_FOR_ID(enable)
STRUCT_FOR_ID(encode)
STRUCT_FOR_ID(encoding)
STRUCT_FOR_ID(end_lineno)
STRUCT_FOR_ID(end_offset)
STRUCT_FOR_ID(errors)
STRUCT_FOR_ID(excepthook)
STRUCT_FOR_ID(exception)
STRUCT_FOR_ID(extend)
STRUCT_FOR_ID(filename)
STRUCT_FOR_ID(fileno)
STRUCT_FOR_ID(fillvalue)
STRUCT_FOR_ID(filters)
STRUCT_FOR_ID(find_class)
STRUCT_FOR_ID(flush)
STRUCT_FOR_ID(genexpr)
STRUCT_FOR_ID(get)
STRUCT_FOR_ID(get_source)
STRUCT_FOR_ID(getattr)
STRUCT_FOR_ID(getstate)
STRUCT_FOR_ID(ignore)
STRUCT_FOR_ID(importlib)
STRUCT_FOR_ID(inf)
STRUCT_FOR_ID(intersection)
STRUCT_FOR_ID(isatty)
STRUCT_FOR_ID(items)
STRUCT_FOR_ID(iter)
STRUCT_FOR_ID(join)
STRUCT_FOR_ID(keys)
STRUCT_FOR_ID(lambda)
STRUCT_FOR_ID(last_traceback)
STRUCT_FOR_ID(last_type)
STRUCT_FOR_ID(last_value)
STRUCT_FOR_ID(latin1)
STRUCT_FOR_ID(line)
STRUCT_FOR_ID(lineno)
STRUCT_FOR_ID(listcomp)
STRUCT_FOR_ID(little)
STRUCT_FOR_ID(locale)
STRUCT_FOR_ID(match)
STRUCT_FOR_ID(metaclass)
STRUCT_FOR_ID(mode)
Expand All @@ -266,9 +293,11 @@ struct _Py_global_strings {
STRUCT_FOR_ID(n_sequence_fields)
STRUCT_FOR_ID(n_unnamed_fields)
STRUCT_FOR_ID(name)
STRUCT_FOR_ID(newlines)
STRUCT_FOR_ID(obj)
STRUCT_FOR_ID(offset)
STRUCT_FOR_ID(onceregistry)
STRUCT_FOR_ID(opcode)
STRUCT_FOR_ID(open)
STRUCT_FOR_ID(parent)
STRUCT_FOR_ID(partial)
Expand Down Expand Up @@ -296,6 +325,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(seek)
STRUCT_FOR_ID(seekable)
STRUCT_FOR_ID(send)
STRUCT_FOR_ID(setcomp)
STRUCT_FOR_ID(setstate)
STRUCT_FOR_ID(sort)
STRUCT_FOR_ID(stderr)
Expand All @@ -307,6 +337,8 @@ struct _Py_global_strings {
STRUCT_FOR_ID(text)
STRUCT_FOR_ID(threading)
STRUCT_FOR_ID(throw)
STRUCT_FOR_ID(top)
STRUCT_FOR_ID(truncate)
STRUCT_FOR_ID(unraisablehook)
STRUCT_FOR_ID(values)
STRUCT_FOR_ID(version)
Expand Down
32 changes: 32 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,16 +651,25 @@ extern "C" {
INIT_STR(anon_module, "<module>"), \
INIT_STR(anon_setcomp, "<setcomp>"), \
INIT_STR(anon_string, "<string>"), \
INIT_STR(anon_unknown, "<unknown>"), \
INIT_STR(close_br, "}"), \
INIT_STR(comma_sep, ", "), \
INIT_STR(dbl_close_br, "}}"), \
INIT_STR(dbl_open_br, "{{"), \
INIT_STR(dbl_percent, "%%"), \
INIT_STR(dot, "."), \
INIT_STR(dot_locals, ".<locals>"), \
INIT_STR(empty, ""), \
INIT_STR(list_err, "list index out of range"), \
INIT_STR(newline, "\n"), \
INIT_STR(open_br, "{"), \
INIT_STR(percent, "%"), \
}, \
.identifiers = { \
INIT_ID(False), \
INIT_ID(Py_Repr), \
INIT_ID(TextIOWrapper), \
INIT_ID(True), \
INIT_ID(WarningMessage), \
INIT_ID(_), \
INIT_ID(__IOBase_closed), \
Expand Down Expand Up @@ -809,7 +818,9 @@ extern "C" {
INIT_ID(__weakref__), \
INIT_ID(__xor__), \
INIT_ID(_abc_impl), \
INIT_ID(_annotation), \
INIT_ID(_blksize), \
INIT_ID(_bootstrap), \
INIT_ID(_dealloc_warn), \
INIT_ID(_finalizing), \
INIT_ID(_find_and_load), \
Expand All @@ -831,46 +842,62 @@ extern "C" {
INIT_ID(big), \
INIT_ID(buffer), \
INIT_ID(builtins), \
INIT_ID(c_call), \
INIT_ID(c_exception), \
INIT_ID(c_return), \
INIT_ID(call), \
INIT_ID(clear), \
INIT_ID(close), \
INIT_ID(closed), \
INIT_ID(code), \
INIT_ID(copy), \
INIT_ID(copyreg), \
INIT_ID(decode), \
INIT_ID(default), \
INIT_ID(defaultaction), \
INIT_ID(dictcomp), \
INIT_ID(difference_update), \
INIT_ID(dispatch_table), \
INIT_ID(displayhook), \
INIT_ID(enable), \
INIT_ID(encode), \
INIT_ID(encoding), \
INIT_ID(end_lineno), \
INIT_ID(end_offset), \
INIT_ID(errors), \
INIT_ID(excepthook), \
INIT_ID(exception), \
INIT_ID(extend), \
INIT_ID(filename), \
INIT_ID(fileno), \
INIT_ID(fillvalue), \
INIT_ID(filters), \
INIT_ID(find_class), \
INIT_ID(flush), \
INIT_ID(genexpr), \
INIT_ID(get), \
INIT_ID(get_source), \
INIT_ID(getattr), \
INIT_ID(getstate), \
INIT_ID(ignore), \
INIT_ID(importlib), \
INIT_ID(inf), \
INIT_ID(intersection), \
INIT_ID(isatty), \
INIT_ID(items), \
INIT_ID(iter), \
INIT_ID(join), \
INIT_ID(keys), \
INIT_ID(lambda), \
INIT_ID(last_traceback), \
INIT_ID(last_type), \
INIT_ID(last_value), \
INIT_ID(latin1), \
INIT_ID(line), \
INIT_ID(lineno), \
INIT_ID(listcomp), \
INIT_ID(little), \
INIT_ID(locale), \
INIT_ID(match), \
INIT_ID(metaclass), \
INIT_ID(mode), \
Expand All @@ -881,9 +908,11 @@ extern "C" {
INIT_ID(n_sequence_fields), \
INIT_ID(n_unnamed_fields), \
INIT_ID(name), \
INIT_ID(newlines), \
INIT_ID(obj), \
INIT_ID(offset), \
INIT_ID(onceregistry), \
INIT_ID(opcode), \
INIT_ID(open), \
INIT_ID(parent), \
INIT_ID(partial), \
Expand Down Expand Up @@ -911,6 +940,7 @@ extern "C" {
INIT_ID(seek), \
INIT_ID(seekable), \
INIT_ID(send), \
INIT_ID(setcomp), \
INIT_ID(setstate), \
INIT_ID(sort), \
INIT_ID(stderr), \
Expand All @@ -922,6 +952,8 @@ extern "C" {
INIT_ID(text), \
INIT_ID(threading), \
INIT_ID(throw), \
INIT_ID(top), \
INIT_ID(truncate), \
INIT_ID(unraisablehook), \
INIT_ID(values), \
INIT_ID(version), \
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ extern struct symtable* _Py_SymtableStringObjectFlags(
int start,
PyCompilerFlags *flags);

extern void _PySymtable_Fini(void);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 1f45536

Please sign in to comment.