Skip to content

Commit 0cf39ef

Browse files
authored
Improve the performance of get_string_prefix (#4742)
1 parent 1f779de commit 0cf39ef

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/black/strings.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ def get_string_prefix(string: str) -> str:
9696
"""
9797
assert_is_leaf_string(string)
9898

99-
prefix = ""
100-
prefix_idx = 0
101-
while string[prefix_idx] in STRING_PREFIX_CHARS:
102-
prefix += string[prefix_idx]
103-
prefix_idx += 1
104-
105-
return prefix
99+
prefix = []
100+
for char in string:
101+
if char in STRING_PREFIX_CHARS:
102+
prefix.append(char)
103+
else:
104+
break
105+
return "".join(prefix)
106106

107107

108108
def assert_is_leaf_string(string: str) -> None:

0 commit comments

Comments
 (0)