Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
da614dcc
Kaydet (Commit)
da614dcc
authored
Şub 10, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Complete an open todo on pickletools -- add a pickle optimizer.
üst
900b7835
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
3 deletions
+38
-3
pickletools.rst
Doc/library/pickletools.rst
+7
-0
pickletools.py
Lib/pickletools.py
+28
-3
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/pickletools.rst
Dosyayı görüntüle @
da614dcc
...
...
@@ -35,3 +35,10 @@ probably won't find the :mod:`pickletools` module relevant.
the opcode's argument; *pos* is the position at which this opcode is located.
*pickle* can be a string or a file-like object.
.. function:: optimize(picklestring)
Returns a new equivalent pickle string after eliminating unused ``PUT``
opcodes. The optimized pickle is shorter, takes less transmission time,
requires less storage space, and unpickles more efficiently.
.. versionadded:: 2.6
Lib/pickletools.py
Dosyayı görüntüle @
da614dcc
...
...
@@ -10,9 +10,7 @@ dis(pickle, out=None, memo=None, indentlevel=4)
Print a symbolic disassembly of a pickle.
'''
__all__
=
[
'dis'
,
'genops'
,
]
__all__
=
[
'dis'
,
'genops'
,
'optimize'
]
# Other ideas:
#
...
...
@@ -1857,6 +1855,33 @@ def genops(pickle):
assert
opcode
.
name
==
'STOP'
break
##############################################################################
# A pickle optimizer.
def
optimize
(
p
):
'Optimize a pickle string by removing unused PUT opcodes'
gets
=
set
()
# set of args used by a GET opcode
puts
=
[]
# (arg, startpos, stoppos) for the PUT opcodes
prevpos
=
None
# set to pos if previous opcode was a PUT
for
opcode
,
arg
,
pos
in
genops
(
p
):
if
prevpos
is
not
None
:
puts
.
append
((
prevarg
,
prevpos
,
pos
))
prevpos
=
None
if
'PUT'
in
opcode
.
name
:
prevarg
,
prevpos
=
arg
,
pos
elif
'GET'
in
opcode
.
name
:
gets
.
add
(
arg
)
# Copy the pickle string except for PUTS without a corresponding GET
s
=
[]
i
=
0
for
arg
,
start
,
stop
in
puts
:
j
=
stop
if
(
arg
in
gets
)
else
start
s
.
append
(
p
[
i
:
j
])
i
=
stop
s
.
append
(
p
[
i
:])
return
''
.
join
(
s
)
##############################################################################
# A symbolic pickle disassembler.
...
...
Misc/NEWS
Dosyayı görüntüle @
da614dcc
...
...
@@ -400,6 +400,9 @@ Core and builtins
Library
-------
- The pickletools module now provides an optimize() function
that eliminates unused PUT opcodes from a pickle string.
- #2021: Allow tempfile.NamedTemporaryFile and SpooledTemporaryFile
to be used in with statements by correctly supporting the context
management protocol.
...
...
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