From d6a335234514bfde378053eb1bf95b6be8262d86 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Wed, 29 May 2002 20:40:22 +0000 Subject: [PATCH] Micro optimizations determined while talking with Tim. --- okascore.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/okascore.c b/okascore.c index b22bda9..c1935fa 100644 --- a/okascore.c +++ b/okascore.c @@ -38,6 +38,10 @@ #define K1 1.2 #define B 0.75 +#ifndef PyTuple_CheckExact +#define PyTuple_CheckExact PyTuple_Check +#endif + static PyObject * score(PyObject *self, PyObject *args) { @@ -74,8 +78,8 @@ score(PyObject *self, PyObject *args) d_and_f = PySequence_GetItem(d2fitems, i); if (d_and_f == NULL) return NULL; - if (!(PyTuple_Check(d_and_f) && - PyTuple_Size(d_and_f) == 2)) { + if (!(PyTuple_CheckExact(d_and_f) && + PyTuple_GET_SIZE(d_and_f) == 2)) { PyErr_SetString(PyExc_TypeError, "d2fitems must produce 2-item tuples"); Py_DECREF(d_and_f); @@ -89,7 +93,7 @@ score(PyObject *self, PyObject *args) Py_DECREF(d_and_f); 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); scaled_int = PyInt_FromLong((long)(tf * idf + 0.5));