minor performance improvement (~2% speedup in unit tests) (#858)
This commit is contained in:
parent
a4399f3054
commit
cbe455ad66
10
black.py
10
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.
|
`line_length` determines how many characters per line are allowed.
|
||||||
"""
|
"""
|
||||||
src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions)
|
src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions)
|
||||||
dst_contents = ""
|
dst_contents = []
|
||||||
future_imports = get_future_imports(src_node)
|
future_imports = get_future_imports(src_node)
|
||||||
if mode.target_versions:
|
if mode.target_versions:
|
||||||
versions = 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 current_line in lines.visit(src_node):
|
||||||
for _ in range(after):
|
for _ in range(after):
|
||||||
dst_contents += str(empty_line)
|
dst_contents.append(str(empty_line))
|
||||||
before, after = elt.maybe_empty_lines(current_line)
|
before, after = elt.maybe_empty_lines(current_line)
|
||||||
for _ in range(before):
|
for _ in range(before):
|
||||||
dst_contents += str(empty_line)
|
dst_contents.append(str(empty_line))
|
||||||
for line in split_line(
|
for line in split_line(
|
||||||
current_line, line_length=mode.line_length, features=split_line_features
|
current_line, line_length=mode.line_length, features=split_line_features
|
||||||
):
|
):
|
||||||
dst_contents += str(line)
|
dst_contents.append(str(line))
|
||||||
return dst_contents
|
return "".join(dst_contents)
|
||||||
|
|
||||||
|
|
||||||
def decode_bytes(src: bytes) -> Tuple[FileContent, Encoding, NewLine]:
|
def decode_bytes(src: bytes) -> Tuple[FileContent, Encoding, NewLine]:
|
||||||
|
Loading…
Reference in New Issue
Block a user