tpunder commented on a change in pull request #698: LUCENE-8834: Cache the 
SortedNumericDocValues.docValueCount() value whenever it is used in a loop
URL: https://github.com/apache/lucene-solr/pull/698#discussion_r290933179
 
 

 ##########
 File path: 
lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene70/Lucene70DocValuesConsumer.java
 ##########
 @@ -158,7 +158,8 @@ void nextBlock() {
     long gcd = 0;
     Set<Long> uniqueValues = new HashSet<>();
     for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc 
= values.nextDoc()) {
-      for (int i = 0, count = values.docValueCount(); i < count; ++i) {
+      final int docValueCount = values.docValueCount();
+      for (int i = 0, count = docValueCount; i < count; ++i) {
 
 Review comment:
   @jpountz I reverted my changes in the case where it was already cached.  It 
looks like that mostly scopes the changes to Solr with the exception of the 
Lucene JoinUtil.
   
   Do you have a caching style preference of doing it inline in the `for` 
expression vs a separate variable before the loop?
   
   I've seen both ways used in the codebase.  For example in 
LatLonPointDistanceComparator.java:
   
   ```java
       if (doc == currentDocs.docID()) {
         setValues();
         int numValues = currentDocs.docValueCount();
         for (int i = 0; i < numValues; i++) {
           long encoded = currentValues[i];
           double docLatitude = decodeLatitude((int)(encoded >> 32));
           double docLongitude = decodeLongitude((int)(encoded & 0xFFFFFFFF));
           minValue = Math.min(minValue, SloppyMath.haversinSortKey(latitude, 
longitude, docLatitude, docLongitude));
         }
       }
   ```
   
   Versus the example you pointed out of:
   
   ```java
   for (int i = 0, count = values.docValueCount(); i < count; ++i) {
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to