[Python-checkins] r77396 - python/branches/py3k/Objects/longobject.c

benjamin.peterson python-checkins at python.org
Sat Jan 9 22:50:11 CET 2010


Author: benjamin.peterson
Date: Sat Jan  9 22:50:11 2010
New Revision: 77396

Log:
simplify string comparison of from_bytes/to_bytes

Modified:
   python/branches/py3k/Objects/longobject.c

Modified: python/branches/py3k/Objects/longobject.c
==============================================================================
--- python/branches/py3k/Objects/longobject.c	(original)
+++ python/branches/py3k/Objects/longobject.c	Sat Jan  9 22:50:11 2010
@@ -4325,10 +4325,9 @@
 	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 @@
 			"'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 @@
 	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 @@
 			"'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,


More information about the Python-checkins mailing list