Skip to content

Commit

Permalink
Small buffer pass optimization as discussed in #395. (#402)
Browse files Browse the repository at this point in the history
Basically ensure the client only does one pass over the buffer instead of two.
Exact thread: #395 (comment)
  • Loading branch information
martinnj committed Jun 9, 2022
1 parent 9cf990f commit 25ec117
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 @@ -1473,10 +1473,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: 2 == len(b"\r\n")
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 25ec117

Please sign in to comment.