summaryrefslogtreecommitdiff
path: root/Lib/asynchat.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2002-03-20 02:22:58 +0000
committerAndrew M. Kuchling <amk@amk.ca>2002-03-20 02:22:58 +0000
commitc63a396c5fc55beeaf3c973f137e160fc844d5a6 (patch)
treed8dccd77d7579176c99e16bd4bdb24417ae068c9 /Lib/asynchat.py
parent913b9078cfeca27c36173ffae8028a089bf13971 (diff)
downloadcpython-git-c63a396c5fc55beeaf3c973f137e160fc844d5a6.tar.gz
A faster version of the find_prefix_at_end() function (that I found in the
last Medusa release) Should be safe as a bugfix candidate, though it's not fixing a bug.
Diffstat (limited to 'Lib/asynchat.py')
-rw-r--r--Lib/asynchat.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/Lib/asynchat.py b/Lib/asynchat.py
index 3b2b37d978..762070f6b9 100644
--- a/Lib/asynchat.py
+++ b/Lib/asynchat.py
@@ -280,20 +280,18 @@ class fifo:
# characters matched.
# for example:
# f_p_a_e ("qwerty\r", "\r\n") => 1
-# f_p_a_e ("qwerty\r\n", "\r\n") => 2
# f_p_a_e ("qwertydkjf", "\r\n") => 0
+# f_p_a_e ("qwerty\r\n", "\r\n") => <undefined>
# this could maybe be made faster with a computed regex?
# [answer: no; circa Python-2.0, Jan 2001]
-# python: 18307/s
+# new python: 28961/s
+# old python: 18307/s
# re: 12820/s
# regex: 14035/s
def find_prefix_at_end (haystack, needle):
- nl = len(needle)
- result = 0
- for i in range (1,nl):
- if haystack[-(nl-i):] == needle[:(nl-i)]:
- result = nl-i
- break
- return result
+ l = len(needle) - 1
+ while l and not haystack.endswith(needle[:l]):
+ l -= 1
+ return l