bpo-32037: Use the INT opcode for 32-bit integers in protocol 0 pickles. (#4407)

This commit is contained in:
Serhiy Storchaka 2017-11-16 09:44:43 +02:00 committed by GitHub
parent 0a2abdfca2
commit 3daaafb700
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 62 deletions

View file

@ -674,7 +674,10 @@ class _Pickler:
else:
self.write(LONG4 + pack("<i", n) + encoded)
return
self.write(LONG + repr(obj).encode("ascii") + b'L\n')
if -0x80000000 <= obj <= 0x7fffffff:
self.write(INT + repr(obj).encode("ascii") + b'\n')
else:
self.write(LONG + repr(obj).encode("ascii") + b'L\n')
dispatch[int] = save_long
def save_float(self, obj):