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

Method memoize

Lib/pickle.py:518–538  ·  view source on GitHub ↗

Store an object in the memo.

(self, obj)

Source from the content-addressed store, hash-verified

516 self.framer.end_framing()
517
518 def memoize(self, obj):
519 """Store an object in the memo."""
520
521 # The Pickler memo is a dictionary mapping object ids to 2-tuples
522 # that contain the Unpickler memo key and the object being memoized.
523 # The memo key is written to the pickle and will become
524 # the key in the Unpickler's memo. The object is stored in the
525 # Pickler memo so that transient objects are kept alive during
526 # pickling.
527
528 # The use of the Unpickler memo length as the memo key is just a
529 # convention. The only requirement is that the memo values be unique.
530 # But there appears no advantage to any other scheme, and this
531 # scheme allows the Unpickler memo to be implemented as a plain (but
532 # growable) array, indexed by memo key.
533 if self.fast:
534 return
535 assert id(obj) not in self.memo
536 idx = len(self.memo)
537 self.write(self.put(idx))
538 self.memo[id(obj)] = idx, obj
539
540 # Return a PUT (BINPUT, LONG_BINPUT) opcode string, with argument i.
541 def put(self, idx):

Callers 10

save_reduceMethod · 0.95
save_bytesMethod · 0.95
save_bytearrayMethod · 0.95
save_strMethod · 0.95
save_tupleMethod · 0.95
save_listMethod · 0.95
save_dictMethod · 0.95
save_setMethod · 0.95
save_frozensetMethod · 0.95
save_globalMethod · 0.95

Calls 3

putMethod · 0.95
idFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected