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
56bed534
Commit
56bed534
authored
Jan 28, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save_tuple(): Minor rewriting, and added a comment about the subtlety
created by recursive tuples.
parent
cf6e1ee9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
Lib/pickle.py
Lib/pickle.py
+13
-8
No files found.
Lib/pickle.py
View file @
56bed534
...
...
@@ -454,21 +454,26 @@ class Pickler:
save
=
self
.
save
memo
=
self
.
memo
d
=
id
(
object
)
write
(
MARK
)
for
element
in
object
:
save
(
element
)
if
len
(
object
)
and
d
in
memo
:
if
object
and
id
(
object
)
in
memo
:
# Subtle. d was not in memo when we entered save_tuple(), so
# the process of saving the tuple's elements must have saved
# the tuple itself: the tuple is recursive. The proper action
# now is to throw away everything we put on the stack, and
# simply GET the tuple (it's already constructed). This check
# could have been done in the "for element" loop instead, but
# recursive tuples are a rare thing.
get
=
self
.
get
(
memo
[
id
(
object
)][
0
])
if
self
.
bin
:
write
(
POP_MARK
+
self
.
get
(
memo
[
d
][
0
]))
return
write
(
POP
*
(
len
(
object
)
+
1
)
+
self
.
get
(
memo
[
d
][
0
]))
write
(
POP_MARK
+
get
)
else
:
# proto 0 -- POP_MARK not available
write
(
POP
*
(
len
(
object
)
+
1
)
+
get
)
return
# No recursion (including the empty-tuple case).
self
.
write
(
TUPLE
)
self
.
memoize
(
object
)
...
...
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