summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-27 21:15:36 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-27 21:15:36 (GMT)
commitbbf63cd05c9bc24964daeee7e5799d0f21091ad3 (patch)
tree889828ae82676a5da68ea402ac3e21998ddf78ab
parent22a449aaccede97288ee98be7e862b957e77a557 (diff)
downloadcpython-bbf63cd05c9bc24964daeee7e5799d0f21091ad3.zip
cpython-bbf63cd05c9bc24964daeee7e5799d0f21091ad3.tar.gz
cpython-bbf63cd05c9bc24964daeee7e5799d0f21091ad3.tar.bz2
Using marshal functions to pack & unpack 1-byte ints is an obscure &
expensive way to spell chr() and ord().
-rw-r--r--Lib/pickle.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index bb739c3..1fc1a65 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -366,12 +366,11 @@ class Pickler:
def save_string(self, object):
if self.bin:
- l = len(object)
- s = mdumps(l)[1:]
- if l < 256:
- self.write(SHORT_BINSTRING + s[0] + object)
+ n = len(object)
+ if n < 256:
+ self.write(SHORT_BINSTRING + chr(n) + object)
else:
- self.write(BINSTRING + s + object)
+ self.write(BINSTRING + mdumps(n)[1:] + object)
else:
self.write(STRING + `object` + '\n')
self.memoize(object)
@@ -380,8 +379,8 @@ class Pickler:
def save_unicode(self, object):
if self.bin:
encoding = object.encode('utf-8')
- l = len(encoding)
- s = mdumps(l)[1:]
+ n = len(encoding)
+ s = mdumps(n)[1:]
self.write(BINUNICODE + s + encoding)
else:
object = object.replace("\\", "\\u005c")
@@ -716,7 +715,7 @@ class Unpickler:
dispatch[BININT] = load_binint
def load_binint1(self):
- self.append(mloads('i' + self.read(1) + '\000\000\000'))
+ self.append(ord(self.read(1)))
dispatch[BININT1] = load_binint1
def load_binint2(self):
@@ -800,7 +799,7 @@ class Unpickler:
dispatch[BINUNICODE] = load_binunicode
def load_short_binstring(self):
- len = mloads('i' + self.read(1) + '\000\000\000')
+ len = ord(self.read(1))
self.append(self.read(len))
dispatch[SHORT_BINSTRING] = load_short_binstring
@@ -950,7 +949,7 @@ class Unpickler:
dispatch[GET] = load_get
def load_binget(self):
- i = mloads('i' + self.read(1) + '\000\000\000')
+ i = ord(self.read(1))
self.append(self.memo[`i`])
dispatch[BINGET] = load_binget
@@ -964,7 +963,7 @@ class Unpickler:
dispatch[PUT] = load_put
def load_binput(self):
- i = mloads('i' + self.read(1) + '\000\000\000')
+ i = ord(self.read(1))
self.memo[`i`] = self.stack[-1]
dispatch[BINPUT] = load_binput