lucene-dev mailing list archives

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

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

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

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message