Skip to content

Commit

Permalink
Small buffer pass optimization as discussed in pinterest#395.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnj committed Jun 7, 2022
1 parent f77bc56 commit 2f6756e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pymemcache/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,10 +1443,13 @@ def _readline(sock, buf):
# Strip the last character from the last chunk.
chunks[-1] = chunks[-1][:-1]
return buf[1:], b"".join(chunks)
elif buf.find(b"\r\n") != -1:
before, sep, after = buf.partition(b"\r\n")
chunks.append(before)
return after, b"".join(chunks)
else:
token_pos = buf.find(b"\r\n")
if token_pos != -1:
# Note, magic constant: Two/2 is the length of the token in find.
before, after = buf[:token_pos], buf[token_pos+2:]
chunks.append(before)
return after, b"".join(chunks)

if buf:
chunks.append(buf)
Expand Down

0 comments on commit 2f6756e

Please sign in to comment.