[Zope-CVS] CVS: Products/ZCTextIndex - okascore.c:1.3

Tim Peters tim.one@comcast.net
Tue, 21 May 2002 12:09:36 -0400


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv31244

Modified Files:
	okascore.c 
Log Message:
Since every score is of the form (tf * idf * 1024. + .5), and idf is
loop-invariant, save a little time by multiplying idf by 1024. outside
the loop.


=== Products/ZCTextIndex/okascore.c 1.2 => 1.3 ===
 		return NULL;
 
+	idf *= 1024.0;	/* float out part of the scaled_int computation */
 	n = PyObject_Length(d2fitems);
 	for (i = 0; i < n; ++i) {
 		PyObject *d_and_f;	/* d2f[i], a (d, f) pair */
@@ -66,7 +67,6 @@
 		PyObject *doclen;	/* ._docweight[d] */
 		double lenweight;
 		double tf;
-		double score;
 		PyObject *scaled_int;
 		int status;
 
@@ -91,8 +91,7 @@
 		lenweight = B_FROM1 + B * PyInt_AsLong(doclen) / meandoclen;
 
 		tf = f * K1_PLUS1 / (f + K1 * lenweight);
-		score = tf * idf;
-		scaled_int = PyInt_FromLong((long)(score * 1024.0 + 0.5));
+		scaled_int = PyInt_FromLong((long)(tf * idf + 0.5));
 		if (scaled_int == NULL)
 			status = -1;
 		else