lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julien Nioche" <Julien.Nio...@lingway.com>
Subject computing size() in frequently used methods
Date Tue, 26 Nov 2002 19:52:45 GMT
Hello,

In the code of BooleanQuery and PhraseQuery loops are made using a size()
method to check the bound. Since the methods of these classes are used very
often, it could be useful to change the code in order to compute the size of
the object only once, store it in an integer and check the bound on that
integer.

For example, the method sumOfSquaredWeights of the class BooleanQuery
currently use the following :

    for (int i = 0 ; i < clauses.size(); i++) {
    ...
    }

which could be replaced by :

 int clausenumber =  clauses.size();

 for (int i = 0 ; i < clausenumber; i++)
 {...}


This kind of modification could be done in almost all the methods of the
classes BooleanQuery and PhraseQuery, providing a small  optimization (I did
not mesure it - but even small optimizations can be useful).

Supposing that the size of the clauses or terms Vectors is not likely to
change during the execution of these methods, this kind of change must be
pretty harmless...

Any opinion on that? Could it have a side effect?


Julien Nioche
www.lingway.com




--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message