10000 Fix #124 · kostyll/msgpack-python@a71a24d · GitHub
[go: up one dir, main page]

Skip to content

Commit a71a24d

Browse files
committed
When using Unpacker as an iterator, after each yield, the internal buffer (_fb_buffer) was compacted by reallocation (done by _fb_consume). When dealing with a lot of small objects, this is very ineffecient. Thus in commit 7eb371f the pure python fallback only reallocated the complete buffer when the iteration stops. When halfway there happens to be data missing in the buffer, we rollback the buffer to the state before this failed call, and raise an OutOfData. This rollback, done by _fb_rollback, did not consider the possibility that the buffer was *not* reallocated. This commit corrects that.
1 parent 8340494 commit a71a24d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

msgpack/fallback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
195195
# the buffer is not "consumed" completely, for efficiency sake.
196196
# Instead, it is done sloppily. To make sure we raise BufferFull at
197197
# the correct moments, we have to keep track of how sloppy we were.
198+
# Furthermore, when the buffer is incomplete (that is: in the case
199+
# we raise an OutOfData) we need to rollback the buffer to the correct
200+
# state, which _fb_slopiness records.
198201
self._fb_sloppiness = 0
199202
self._max_buffer_size = max_buffer_size or 2**31-1
200203
if read_size > self._max_buffer_size:
@@ -283,7 +286,7 @@ def read_bytes(self, n):
283286

284287
def _fb_rollback(self):
285288
self._fb_buf_i = 0
286-
self._fb_buf_o = 0
289+
self._fb_buf_o = self._fb_sloppiness
287290

288291
def _fb_get_extradata(self):
289292
bufs = self._fb_buffers[self._fb_buf_i:]

0 commit comments

Comments
 (0)
0