aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-10-14 15:31:12 -0700
committerGravatar MarkKoz <[email protected]>2020-10-14 15:31:12 -0700
commit1bbb8a5a9236582232472b90ccc217380fdfef6f (patch)
treeab92e9b6bb8076c4c80df8920d3ce11d8e161874
parentMerge master and fix conflicts (diff)
Utils: clarify why has_lines counts by splitting by newlines
-rw-r--r--bot/utils/helpers.py1
1 files changed, 1 insertions, 0 deletions
diff --git a/bot/utils/helpers.py b/bot/utils/helpers.py
index b5c13ac9e..3501a3933 100644
--- a/bot/utils/helpers.py
+++ b/bot/utils/helpers.py
@@ -20,6 +20,7 @@ def find_nth_occurrence(string: str, substring: str, n: int) -> Optional[int]:
def has_lines(string: str, count: int) -> bool:
"""Return True if `string` has at least `count` lines."""
+ # Benchmarks show this is significantly faster than using str.count("\n") or a for loop & break.
split = string.split("\n", count - 1)
# Make sure the last part isn't empty, which would happen if there was a final newline.