Skip to content

Commit 21d7b01

Browse files
committed
pythongh-126317: Fix to avoid calling the len function twice
1 parent 4fa459b commit 21d7b01

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Lib/pickle.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ def _batch_appends(self, items, obj):
10351035

10361036
start = 0
10371037
for batch in batched(items, self._BATCHSIZE):
1038-
if len(batch) != 1:
1038+
batch_len = len(batch)
1039+
if batch_len != 1:
10391040
write(MARK)
10401041
for i, x in enumerate(batch, start):
10411042
try:
@@ -1051,7 +1052,7 @@ def _batch_appends(self, items, obj):
10511052
exc.add_note(f'when serializing {_T(obj)} item {start}')
10521053
raise
10531054
write(APPEND)
1054-
start += len(batch)
1055+
start += batch_len
10551056

10561057
def save_dict(self, obj):
10571058
if self.bin:

0 commit comments

Comments
 (0)