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

Class ZeroCopyBytearray

Lib/test/picklecommon.py:337–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335
336
337class ZeroCopyBytearray(bytearray):
338 readonly = False
339 c_contiguous = True
340 f_contiguous = True
341 zero_copy_reconstruct = True
342
343 def __reduce_ex__(self, protocol):
344 if protocol >= 5:
345 import pickle
346 return type(self)._reconstruct, (pickle.PickleBuffer(self),), None
347 else:
348 return type(self)._reconstruct, (bytes(self),)
349
350 def __repr__(self):
351 return "{}({!r})".format(self.__class__.__name__, bytes(self))
352
353 __str__ = __repr__
354
355 @classmethod
356 def _reconstruct(cls, obj):
357 with memoryview(obj) as m:
358 obj = m.obj
359 if type(obj) is cls:
360 # Zero-copy
361 return obj
362 else:
363 return cls(obj)
364
365
366# For test_nested_names

Callers 1

buffer_like_objectsMethod · 0.85

Calls

no outgoing calls

Tested by 1

buffer_like_objectsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…