Skip to content

Commit

Permalink
Minor speedup for test fn toy_multisplit_original.
Browse files Browse the repository at this point in the history
Why bother making toy_multisplit_original faster?
Because, as folks answer about why they climbed Everest--it was there.
Also, maybe there's some life left in the old girl yet.
  • Loading branch information
larryhastings committed Sep 7, 2023
1 parent 61c2c77 commit a9ef228
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,15 +1002,17 @@ def flush_word():
word.clear()

while s:
longest_separator = 0
longest_separator_length = 0
longest_separator = None
for sep in separators:
if s.startswith(sep) and (len(sep) > longest_separator):
longest_separator = len(sep)
length = len(sep)
if s.startswith(sep) and (length > longest_separator_length):
longest_separator = sep
longest_separator_length = length
if longest_separator:
flush_word()
segments.append(s[:longest_separator])
s = s[longest_separator:]
longest_separator = 0
segments.append(longest_separator)
s = s[longest_separator_length:]
continue
word.append(s[:1])
s = s[1:]
Expand Down Expand Up @@ -1123,7 +1125,10 @@ def flush_word():

return segments

# quickly test toy_multisplit
#
# you know what's a good idea? testing!
# let's quickly test toy_multisplit to make sure *it* works.
#

want_prints = False
# want_prints = True
Expand Down Expand Up @@ -1204,7 +1209,6 @@ def t(s, seps, expected):
['', ' ', '', ' ', '', '\t', '', ' ', 'abc', ' ', 'de', ' ', '', ' ', 'fgh', ' ', '', '\n', '', '\t', 'ijk', ' ', '', ' ', '', ' ', '', ' ', 'lm', ' ', '', ' ', ''])



def multisplit_tester(s, separators=None):
"""
s is the test string you want split.
Expand Down

0 comments on commit a9ef228

Please sign in to comment.