diff --git a/components/script_bindings/codegen/CodegenRust.py b/components/script_bindings/codegen/codegen.py similarity index 99% rename from components/script_bindings/codegen/CodegenRust.py rename to components/script_bindings/codegen/codegen.py index 61477a8fde0..bf609cf563b 100644 --- a/components/script_bindings/codegen/CodegenRust.py +++ b/components/script_bindings/codegen/codegen.py @@ -36,7 +36,7 @@ from WebIDL import ( IDLWrapperType, ) -from Configuration import ( +from configuration import ( Configuration, Descriptor, DescriptorProvider, @@ -265,27 +265,7 @@ def indent(s, indentLevel=2): return s return re.sub(lineStartDetector, indentLevel * " ", s) - -# dedent() and fill() are often called on the same string multiple -# times. We want to memoize their return values so we don't keep -# recomputing them all the time. -def memoize(fn): - """ - Decorator to memoize a function of one argument. The cache just - grows without bound. - """ - cache = {} - - @functools.wraps(fn) - def wrapper(arg): - retval = cache.get(arg) - if retval is None: - retval = cache[arg] = fn(arg) - return retval - return wrapper - - -@memoize +@functools.cache def dedent(s): """ Remove all leading whitespace from s, and remove a blank line @@ -301,7 +281,7 @@ def dedent(s): fill_multiline_substitution_re = re.compile(r"( *)\$\*{(\w+)}(\n)?") -@memoize +@functools.cache def compile_fill_template(template): """ Helper function for fill(). Given the template string passed to fill(), diff --git a/components/script_bindings/codegen/Configuration.py b/components/script_bindings/codegen/configuration.py similarity index 100% rename from components/script_bindings/codegen/Configuration.py rename to components/script_bindings/codegen/configuration.py diff --git a/components/script_bindings/codegen/run.py b/components/script_bindings/codegen/run.py index 94f75b0153f..2df38ccc31a 100644 --- a/components/script_bindings/codegen/run.py +++ b/components/script_bindings/codegen/run.py @@ -27,8 +27,8 @@ def main(): config_file = "Bindings.conf" import WebIDL - from Configuration import Configuration - from CodegenRust import CGBindingRoot, CGConcreteBindingRoot + from configuration import Configuration + from codegen import CGBindingRoot, CGConcreteBindingRoot parser = WebIDL.Parser(make_dir(os.path.join(out_dir, "cache"))) webidls = [name for name in os.listdir(webidls_dir) if name.endswith(".webidl")] @@ -91,7 +91,7 @@ def make_dir(path): def generate(config, name, filename): - from CodegenRust import GlobalGenRoots + from codegen import GlobalGenRoots root = getattr(GlobalGenRoots, name)(config) code = root.define() with open(filename, "wb") as f: