MCPcopy Index your code
hub / github.com/python/cpython / _batch_setitems

Method _batch_setitems

Lib/pickle.py:1084–1119  ·  view source on GitHub ↗
(self, items, obj)

Source from the content-addressed store, hash-verified

1082 dispatch[dict] = save_dict
1083
1084 def _batch_setitems(self, items, obj):
1085 # Helper to batch up SETITEMS sequences; proto >= 1 only
1086 save = self.save
1087 write = self.write
1088
1089 if not self.bin:
1090 for k, v in items:
1091 save(k)
1092 try:
1093 save(v)
1094 except BaseException as exc:
1095 exc.add_note(f'when serializing {_T(obj)} item {k!r}')
1096 raise
1097 write(SETITEM)
1098 return
1099
1100 for batch in batched(items, self._BATCHSIZE):
1101 if len(batch) != 1:
1102 write(MARK)
1103 for k, v in batch:
1104 save(k)
1105 try:
1106 save(v)
1107 except BaseException as exc:
1108 exc.add_note(f'when serializing {_T(obj)} item {k!r}')
1109 raise
1110 write(SETITEMS)
1111 else:
1112 k, v = batch[0]
1113 save(k)
1114 try:
1115 save(v)
1116 except BaseException as exc:
1117 exc.add_note(f'when serializing {_T(obj)} item {k!r}')
1118 raise
1119 write(SETITEM)
1120
1121 def save_set(self, obj):
1122 save = self.save

Callers 2

save_reduceMethod · 0.95
save_dictMethod · 0.95

Calls 2

_TFunction · 0.85
writeFunction · 0.70

Tested by

no test coverage detected