summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-02-02 14:54:45 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-02-02 14:54:45 (GMT)
commit196a7bc1ea8842b8c73954a625a0f5a80ef011b9 (patch)
tree1eb58a7fcda046c6412ab4481213e205295f9135 /Objects
parentc0f59ad1455a53b6a8a9f09620ae4283e4df9f26 (diff)
downloadcpython-196a7bc1ea8842b8c73954a625a0f5a80ef011b9.zip
cpython-196a7bc1ea8842b8c73954a625a0f5a80ef011b9.tar.gz
cpython-196a7bc1ea8842b8c73954a625a0f5a80ef011b9.tar.bz2
Issue #29421: Make int.to_bytes() and int.from_bytes() slightly faster
(10-20% for small integers).
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index f37fbd7..0bf6cee 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -22,6 +22,9 @@ class int "PyObject *" "&PyLong_Type"
#define NSMALLNEGINTS 5
#endif
+_Py_IDENTIFIER(little);
+_Py_IDENTIFIER(big);
+
/* convert a PyLong of size 1, 0 or -1 to an sdigit */
#define MEDIUM_VALUE(x) (assert(-1 <= Py_SIZE(x) && Py_SIZE(x) <= 1), \
Py_SIZE(x) < 0 ? -(sdigit)(x)->ob_digit[0] : \
@@ -5198,9 +5201,9 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,
int little_endian;
PyObject *bytes;
- if (_PyUnicode_EqualToASCIIString(byteorder, "little"))
+ if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little))
little_endian = 1;
- else if (_PyUnicode_EqualToASCIIString(byteorder, "big"))
+ else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,
@@ -5258,9 +5261,9 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
int little_endian;
PyObject *long_obj, *bytes;
- if (_PyUnicode_EqualToASCIIString(byteorder, "little"))
+ if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little))
little_endian = 1;
- else if (_PyUnicode_EqualToASCIIString(byteorder, "big"))
+ else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,