Commit fb9af5c5 authored by Fred Drake's avatar Fred Drake

Micro optimizations determined while talking with Tim.

parent d0a75ba3
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#define K1 1.2 #define K1 1.2
#define B 0.75 #define B 0.75
#ifndef PyTuple_CheckExact
#define PyTuple_CheckExact PyTuple_Check
#endif
static PyObject * static PyObject *
score(PyObject *self, PyObject *args) score(PyObject *self, PyObject *args)
{ {
...@@ -74,8 +78,8 @@ score(PyObject *self, PyObject *args) ...@@ -74,8 +78,8 @@ score(PyObject *self, PyObject *args)
d_and_f = PySequence_GetItem(d2fitems, i); d_and_f = PySequence_GetItem(d2fitems, i);
if (d_and_f == NULL) if (d_and_f == NULL)
return NULL; return NULL;
if (!(PyTuple_Check(d_and_f) && if (!(PyTuple_CheckExact(d_and_f) &&
PyTuple_Size(d_and_f) == 2)) { PyTuple_GET_SIZE(d_and_f) == 2)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"d2fitems must produce 2-item tuples"); "d2fitems must produce 2-item tuples");
Py_DECREF(d_and_f); Py_DECREF(d_and_f);
...@@ -89,7 +93,7 @@ score(PyObject *self, PyObject *args) ...@@ -89,7 +93,7 @@ score(PyObject *self, PyObject *args)
Py_DECREF(d_and_f); Py_DECREF(d_and_f);
return NULL; return NULL;
} }
lenweight = B_FROM1 + B * PyInt_AsLong(doclen) / meandoclen; lenweight = B_FROM1 + B * PyInt_AS_LONG(doclen) / meandoclen;
tf = f * K1_PLUS1 / (f + K1 * lenweight); tf = f * K1_PLUS1 / (f + K1 * lenweight);
scaled_int = PyInt_FromLong((long)(tf * idf + 0.5)); scaled_int = PyInt_FromLong((long)(tf * idf + 0.5));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment