Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
450ae573
Commit
450ae573
authored
Jun 12, 2009
by
Alexandre Vassalotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make pickling of OrderedDict instances more efficient.
parent
f0c9e46c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
Lib/collections.py
Lib/collections.py
+6
-4
Lib/test/test_collections.py
Lib/test/test_collections.py
+2
-2
No files found.
Lib/collections.py
View file @
450ae573
...
...
@@ -99,14 +99,16 @@ class OrderedDict(dict, MutableMapping):
def
__reduce__
(
self
):
'Return state information for pickling'
items
=
[[
k
,
self
[
k
]]
for
k
in
self
]
dictitems
=
self
.
iteritems
()
tmp
=
self
.
__map
,
self
.
__root
del
self
.
__map
,
self
.
__root
inst_dict
=
vars
(
self
).
copy
()
self
.
__map
,
self
.
__root
=
tmp
if
inst_dict
:
return
(
self
.
__class__
,
(
items
,),
inst_dict
)
return
self
.
__class__
,
(
items
,)
# Set the state item to None when the dictionary is empty. This saves
# about 2 opcodes when the object is pickled.
if
not
inst_dict
:
inst_dict
=
None
return
(
self
.
__class__
,
(),
inst_dict
,
None
,
dictitems
)
setdefault
=
MutableMapping
.
setdefault
update
=
MutableMapping
.
update
...
...
Lib/test/test_collections.py
View file @
450ae573
...
...
@@ -795,9 +795,9 @@ class TestOrderedDict(unittest.TestCase):
# do not save instance dictionary if not needed
pairs
=
[(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)]
od
=
OrderedDict
(
pairs
)
self
.
assertEqual
(
len
(
od
.
__reduce__
()),
2
)
od
.
x
=
10
self
.
assertEqual
(
len
(
od
.
__reduce__
()),
3
)
self
.
assertGreaterEqual
(
len
(
od
.
__reduce__
()),
2
)
self
.
assertLessEqual
(
len
(
od
.
__reduce__
()),
5
)
def
test_repr
(
self
):
od
=
OrderedDict
([(
'c'
,
1
),
(
'b'
,
2
),
(
'a'
,
3
),
(
'd'
,
4
),
(
'e'
,
5
),
(
'f'
,
6
)])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment