summaryrefslogtreecommitdiff
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-01-09 21:50:11 +0000
committerBenjamin Peterson <benjamin@python.org>2010-01-09 21:50:11 +0000
commit0c0e229dd0a12eed81e08917339f2f11e12be96c (patch)
tree47d9024d3ecb5a21b6333557e9e97ae03d86a935 /Objects/longobject.c
parent8667a9b6ea414fb78c0c71d411d86c5cfffbf549 (diff)
downloadcpython-git-0c0e229dd0a12eed81e08917339f2f11e12be96c.tar.gz
simplify string comparison of from_bytes/to_bytes
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index cfe7b5c748..afac856cd0 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -4325,10 +4325,9 @@ long_to_bytes(PyLongObject *v, PyObject *args, PyObject *kwds)
int little_endian;
int is_signed;
PyObject *bytes;
- static PyObject *little_str = NULL, *big_str = NULL;
static char *kwlist[] = {"length", "byteorder", "signed", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "nO|O:to_bytes", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "nU|O:to_bytes", kwlist,
&length, &byteorder_str,
&is_signed_obj))
return NULL;
@@ -4338,16 +4337,10 @@ long_to_bytes(PyLongObject *v, PyObject *args, PyObject *kwds)
"'signed' is a keyword-only argument");
return NULL;
}
- if (little_str == NULL) {
- little_str = PyUnicode_InternFromString("little");
- big_str = PyUnicode_InternFromString("big");
- if (little_str == NULL || big_str == NULL)
- return NULL;
- }
- if (PyObject_RichCompareBool(byteorder_str, little_str, Py_EQ))
+ if (!PyUnicode_CompareWithASCIIString(byteorder_str, "little"))
little_endian = 1;
- else if (PyObject_RichCompareBool(byteorder_str, big_str, Py_EQ))
+ else if (!PyUnicode_CompareWithASCIIString(byteorder_str, "big"))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,
@@ -4414,10 +4407,9 @@ long_from_bytes(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *obj;
PyObject *bytes;
PyObject *long_obj;
- static PyObject *little_str = NULL, *big_str = NULL;
static char *kwlist[] = {"bytes", "byteorder", "signed", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:from_bytes", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OU|O:from_bytes", kwlist,
&obj, &byteorder_str,
&is_signed_obj))
return NULL;
@@ -4427,16 +4419,10 @@ long_from_bytes(PyTypeObject *type, PyObject *args, PyObject *kwds)
"'signed' is a keyword-only argument");
return NULL;
}
- if (little_str == NULL) {
- little_str = PyUnicode_InternFromString("little");
- big_str = PyUnicode_InternFromString("big");
- if (little_str == NULL || big_str == NULL)
- return NULL;
- }
- if (PyObject_RichCompareBool(byteorder_str, little_str, Py_EQ))
+ if (!PyUnicode_CompareWithASCIIString(byteorder_str, "little"))
little_endian = 1;
- else if (PyObject_RichCompareBool(byteorder_str, big_str, Py_EQ))
+ else if (!PyUnicode_CompareWithASCIIString(byteorder_str, "big"))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,