| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
| |
|
|
|
|
| |
_instantiate() method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
on the type instead of self.save(t). This defeated the purpose of
NEWOBJ, because it didn't generate a BINGET opcode when t was already
memoized; but moreover, it would generate multiple BINPUT opcodes for
the same type! pickletools.dis() doesn't like this.
How I found this? I was playing with picklesize.py in the datetime
sandbox, and noticed that protocol 2 pickles for multiple objects were
in fact larger than protocol 1 pickles! That was suspicious, so I
decided to disassemble one of the pickles.
This really needs a unit test, but I'm exhausted. I'll be late for
work as it is. :-(
|
| |
|
|
|
|
|
|
|
|
|
| |
the same function, don't save the state or write a BUILD opcode. This
is so that a type (e.g. datetime :-) can support protocol 2 using
__getnewargs__ while also supporting protocol 0 and 1 using
__getstate__. (Without this, the state would be pickled twice with
protocol 2, unless __getstate__ is defined to return None, which
breaks protocol 0 and 1.)
|
| |
|
|
|
|
|
|
|
|
| |
types. The special handling for these can now be removed from save_newobj().
Add some testing for this.
Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
|
| |
|
| |
|
|
|
|
| |
pickletools: Import decode_long from pickle instead of duplicating it.
|
|
|
|
| |
__getnewargs__ method.
|
|
|
|
| |
Also tidied up a few lines, got rid of apply(), added a comment.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
object.__reduce__, do a getattr() on the class so we can explicitly
test for it. The reduce()-calling code becomes a bit more regular as
a result.
Also add support slots: if an object has slots, the default state is
(dict, slots) where dict is the __dict__ or None, and slots is a dict
mapping slot names to slot values. We do a best-effort approach to
find slot names, assuming the __slots__ fields of classes aren't
modified after class definition time to misrepresent the actual list
of slots defined by a class.
|
|
|
|
|
|
| |
possibility of calling save_reduce(). Add a special hack for this.
The tests for this are much simpler now (no __getstate__ or
__getnewargs__ needed).
|
|
|
|
| |
after checking for __reduce__.
|
|
|
|
| |
fixed a bug in load_newobj().
|
| |
|
| |
|
|
|
|
| |
was used before string-escape codecs were added to the core.)
|
|
|
|
|
|
| |
checks to save_reduce(), which can also be called from a subclass.)
Also tweaked some more comments.
|
| |
|
|
|
|
|
|
|
| |
be one of 0, 1 or 2).
I should note that the previous checkin also added NEWOBJ support to
the unpickler -- but there's nothing yet that generates this.
|
|
|
|
|
| |
type 'object'. Also minor docstring tweakage, and rearranged a few
lines in save().
|
| |
|
|
|
|
| |
control flow had to be simplified.
|
|
|
|
|
| |
incorrect for recursive tuples. Tried to repair; seems to work OK, but
there are no checked-in tests for this yet.
|
|
|
|
| |
NEWFALSE and NEWTRUE.
|
|
|
|
| |
Also moved the special case for empty tuples from save() to save_tuple().
|
|
|
|
|
| |
of my recent XXX comment, taking a (what appears to be vanishingly small)
chance and calling self.memoize() instead.
|
| |
|
| |
|
| |
|
|
|
|
|
| |
marshal.loads() beats struct.unpack()! Possibly because the latter
creates a one-tuple. :-(
|
|
|
|
|
| |
40% faster than marshal.dumps(x)[1:]! (That's not counting the
module attribute lookups, which can be avoided in either case.)
|
|
|
|
| |
created by recursive tuples.
|
| |
|
| |
|
|
|
|
|
| |
iteritems() instead of materializing a (possibly giant) list of the
items.
|
|
|
|
| |
The code is much easier to follow now, and I bet it's faster too.
|
| |
|
| |
|
|
|
|
|
| |
make the bin-vs-not-bin order consistent with what other routines try to
do (they almost all handle the bin case first).
|
|
|
|
|
|
| |
some notion of low-level efficiency. Undid that, but left one routine
alone: save_inst() claims it has a reason for not using memoize().
I don't understand that comment, so added an XXX comment there.
|
|
|
|
|
| |
belongs. This is a much smaller change than it may appear: the bulk
of the function merely got unindented by one level.
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
then the embedded argument consumes at least 256 bytes. The difference
between a 3-byte prefix (LONG2 + 2 bytes) and a 5-byte prefix (LONG4 +
4 bytes) is at worst less than 1%. Note that binary strings and binary
Unicode strings also have only "size is 1 byte, or size is 4 bytes?"
flavors, and I expect for the same reason. The only place a 2-byte
thingie was used was in BININT2, where the 2 bytes make up the *entire*
embedded argument (and now EXT2 also does this); that's a large savings
over 4 bytes, because the total opcode+argument size is so small in
the BININT2/EXT2 case.
Removed the TAKEN_FROM_ARGUMENT "number of bytes" code, and bifurcated it
into TAKEN_FROM_ARGUMENT1 and TAKEN_FROM_ARGUMENT4. Now there's enough
info in ArgumentDescriptor objects to deduce the # of bytes consumed by
each opcode.
Rearranged the order in which proto2 opcodes are listed in pickle.py.
|