]> granicus.if.org Git - python/commitdiff
needforspeed: use METH_O for argument handling, which made partition some
authorFredrik Lundh <fredrik@pythonware.com>
Fri, 26 May 2006 09:46:59 +0000 (09:46 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Fri, 26 May 2006 09:46:59 +0000 (09:46 +0000)
~15% faster for the current tests (which is noticable faster than a corre-
sponding find call).  thanks to neal-who-never-sleeps for the tip.

Objects/stringobject.c
Objects/unicodeobject.c

index 0e0af89e5fad6647ec8f99553d1ce063f081a9f2..0aa1e5b38903a6ec3ceddf688a57004066675e52 100644 (file)
@@ -1606,15 +1606,12 @@ the separator itself, and the part after it.  If the separator is not\n\
 found, returns S and two empty strings.");
 
 static PyObject *
-string_partition(PyStringObject *self, PyObject *args)
+string_partition(PyStringObject *self, PyObject *sep_obj)
 {
        Py_ssize_t len = PyString_GET_SIZE(self), sep_len, pos;
        const char *str = PyString_AS_STRING(self), *sep;
-       PyObject *sep_obj;
        PyObject * out;
 
-       if (!PyArg_ParseTuple(args, "O:partition", &sep_obj))
-               return NULL;
        if (PyString_Check(sep_obj)) {
                sep = PyString_AS_STRING(sep_obj);
                sep_len = PyString_GET_SIZE(sep_obj);
@@ -3969,8 +3966,7 @@ string_methods[] = {
        {"count", (PyCFunction)string_count, METH_VARARGS, count__doc__},
        {"endswith", (PyCFunction)string_endswith, METH_VARARGS,
         endswith__doc__},
-       {"partition", (PyCFunction)string_partition, METH_VARARGS,
-        partition__doc__},
+       {"partition", (PyCFunction)string_partition, METH_O, partition__doc__},
        {"find", (PyCFunction)string_find, METH_VARARGS, find__doc__},
        {"index", (PyCFunction)string_index, METH_VARARGS, index__doc__},
        {"lstrip", (PyCFunction)string_lstrip, METH_VARARGS, lstrip__doc__},
index 770224884cc6923934d7e851772a3985d6d13a9c..82914008e0ac752bd49df78112f1cea4cc019689 100644 (file)
@@ -6357,13 +6357,8 @@ the separator itself, and the part after it.  If the separator is not\n\
 found, returns S and two empty strings.");
 
 static PyObject*
-unicode_partition(PyUnicodeObject *self, PyObject *args)
+unicode_partition(PyUnicodeObject *self, PyObject *separator)
 {
-    PyObject *separator;
-
-    if (!PyArg_ParseTuple(args, "O:partition", &separator))
-        return NULL;
-
     return PyUnicode_Partition((PyObject *)self, separator);
 }
 
@@ -6620,7 +6615,7 @@ static PyMethodDef unicode_methods[] = {
     {"count", (PyCFunction) unicode_count, METH_VARARGS, count__doc__},
     {"expandtabs", (PyCFunction) unicode_expandtabs, METH_VARARGS, expandtabs__doc__},
     {"find", (PyCFunction) unicode_find, METH_VARARGS, find__doc__},
-    {"partition", (PyCFunction) unicode_partition, METH_VARARGS, partition__doc__},
+    {"partition", (PyCFunction) unicode_partition, METH_O, partition__doc__},
     {"index", (PyCFunction) unicode_index, METH_VARARGS, index__doc__},
     {"ljust", (PyCFunction) unicode_ljust, METH_VARARGS, ljust__doc__},
     {"lower", (PyCFunction) unicode_lower, METH_NOARGS, lower__doc__},