Skip to content

Commit

Permalink
perf: remove the use of a dict to store rewriters
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 2, 2021
1 parent 1d93380 commit 72a8fd3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions protoletariat/fdsetgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def fix_imports(
exclude_imports_glob: Sequence[str],
) -> None:
"""Fix imports from protoc/buf generated code."""
rewriters = {}
fdset = FileDescriptorSet.FromString(self.generate_file_descriptor_set_bytes())

for fd in fdset.file:
Expand All @@ -50,7 +49,7 @@ def fix_imports(
continue

fd_name = _remove_proto_suffix(name)
rewriters[fd_name] = rewriter = ASTImportRewriter()
rewriter = ASTImportRewriter()
# services live outside of the corresponding generated Python
# module, but they import it so we register a rewrite for the
# current proto as a dependency of itself to handle the case
Expand All @@ -74,7 +73,7 @@ def fix_imports(
except FileNotFoundError:
pass
else:
new_code = rewriters[fd_name].rewrite(raw_code)
new_code = rewriter.rewrite(raw_code)
overwrite_callback(python_file, new_code)

if create_package:
Expand Down

0 comments on commit 72a8fd3

Please sign in to comment.