Optim: test that could be done once has been extracted from the loop
authorPierre-Emmanuel Viel <p.emmanuel.viel@gmail.com>
Sat, 16 May 2020 22:06:47 +0000 (00:06 +0200)
committerPierre-Emmanuel Viel <p.emmanuel.viel@gmail.com>
Tue, 23 Jun 2020 13:43:38 +0000 (15:43 +0200)
modules/flann/include/opencv2/flann/kdtree_single_index.h

index fa38f9f..e03226b 100644 (file)
@@ -548,11 +548,19 @@ private:
         /* If this is a leaf node, then do check and return. */
         if ((node->child1 == NULL)&&(node->child2 == NULL)) {
             DistanceType worst_dist = result_set.worstDist();
-            for (int i=node->left; i<node->right; ++i) {
-                int index = reorder_ ? i : vind_[i];
-                DistanceType dist = distance_(vec, data_[index], dim_, worst_dist);
-                if (dist<worst_dist) {
-                    result_set.addPoint(dist,vind_[i]);
+            if (reorder_) {
+                for (int i=node->left; i<node->right; ++i) {
+                    DistanceType dist = distance_(vec, data_[i], dim_, worst_dist);
+                    if (dist<worst_dist) {
+                        result_set.addPoint(dist,vind_[i]);
+                    }
+                }
+            } else {
+                for (int i=node->left; i<node->right; ++i) {
+                    DistanceType dist = distance_(vec, data_[vind_[i]], dim_, worst_dist);
+                    if (dist<worst_dist) {
+                        result_set.addPoint(dist,vind_[i]);
+                    }
                 }
             }
             return;