MCPcopy Index your code
hub / github.com/RustPython/RustPython / _batch_setitems

Method _batch_setitems

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

Source from the content-addressed store, hash-verified

1066 dispatch[dict] = save_dict
1067
1068 def _batch_setitems(self, items, obj):
1069 # Helper to batch up SETITEMS sequences; proto >= 1 only
1070 save = self.save
1071 write = self.write
1072
1073 if not self.bin:
1074 for k, v in items:
1075 save(k)
1076 try:
1077 save(v)
1078 except BaseException as exc:
1079 exc.add_note(f'when serializing {_T(obj)} item {k!r}')
1080 raise
1081 write(SETITEM)
1082 return
1083
1084 for batch in batched(items, self._BATCHSIZE):
1085 if len(batch) != 1:
1086 write(MARK)
1087 for k, v in batch:
1088 save(k)
1089 try:
1090 save(v)
1091 except BaseException as exc:
1092 exc.add_note(f'when serializing {_T(obj)} item {k!r}')
1093 raise
1094 write(SETITEMS)
1095 else:
1096 k, v = batch[0]
1097 save(k)
1098 try:
1099 save(v)
1100 except BaseException as exc:
1101 exc.add_note(f'when serializing {_T(obj)} item {k!r}')
1102 raise
1103 write(SETITEM)
1104
1105 def save_set(self, obj):
1106 save = self.save

Callers 2

save_reduceMethod · 0.95
save_dictMethod · 0.95

Calls 4

_TFunction · 0.85
lenFunction · 0.85
add_noteMethod · 0.80
writeFunction · 0.70

Tested by

no test coverage detected