From cbe455ad6637897227fb0bb95660d63862f592b0 Mon Sep 17 00:00:00 2001 From: Michael Flaxman Date: Tue, 21 May 2019 22:02:17 -0500 Subject: [PATCH 1/1] minor performance improvement (~2% speedup in unit tests) (#858) --- black.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/black.py b/black.py index 728b084..7ede0b4 100644 --- a/black.py +++ b/black.py @@ -707,7 +707,7 @@ def format_str(src_contents: str, *, mode: FileMode) -> FileContent: `line_length` determines how many characters per line are allowed. """ src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions) - dst_contents = "" + dst_contents = [] future_imports = get_future_imports(src_node) if mode.target_versions: versions = mode.target_versions @@ -730,15 +730,15 @@ def format_str(src_contents: str, *, mode: FileMode) -> FileContent: } for current_line in lines.visit(src_node): for _ in range(after): - dst_contents += str(empty_line) + dst_contents.append(str(empty_line)) before, after = elt.maybe_empty_lines(current_line) for _ in range(before): - dst_contents += str(empty_line) + dst_contents.append(str(empty_line)) for line in split_line( current_line, line_length=mode.line_length, features=split_line_features ): - dst_contents += str(line) - return dst_contents + dst_contents.append(str(line)) + return "".join(dst_contents) def decode_bytes(src: bytes) -> Tuple[FileContent, Encoding, NewLine]: -- 2.39.5