Store an object in the memo.
(self, obj)
| 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): |
no test coverage detected