MCPcopy Create free account
hub / github.com/RustPython/RustPython / save_long

Method save_long

Lib/pickle.py:806–834  ·  view source on GitHub ↗
(self, obj)

Source from the content-addressed store, hash-verified

804 dispatch[bool] = save_bool
805
806 def save_long(self, obj):
807 if self.bin:
808 # If the int is small enough to fit in a signed 4-byte 2's-comp
809 # format, we can store it more efficiently than the general
810 # case.
811 # First one- and two-byte unsigned ints:
812 if obj >= 0:
813 if obj <= 0xff:
814 self.write(BININT1 + pack("<B", obj))
815 return
816 if obj <= 0xffff:
817 self.write(BININT2 + pack("<H", obj))
818 return
819 # Next check for 4-byte signed ints:
820 if -0x80000000 <= obj <= 0x7fffffff:
821 self.write(BININT + pack("<i", obj))
822 return
823 if self.proto >= 2:
824 encoded = encode_long(obj)
825 n = len(encoded)
826 if n < 256:
827 self.write(LONG1 + pack("<B", n) + encoded)
828 else:
829 self.write(LONG4 + pack("<i", n) + encoded)
830 return
831 if -0x80000000 <= obj <= 0x7fffffff:
832 self.write(INT + repr(obj).encode("ascii") + b'\n')
833 else:
834 self.write(LONG + repr(obj).encode("ascii") + b'L\n')
835 dispatch[int] = save_long
836
837 def save_float(self, obj):

Callers

nothing calls this directly

Calls 6

packFunction · 0.90
encode_longFunction · 0.85
lenFunction · 0.85
reprFunction · 0.85
writeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected