Skip to content

Commit 29f883f

Browse files
committed
Optim: test that could be done once has been extracted from the loop
1 parent 7fae2e8 commit 29f883f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

modules/flann/include/opencv2/flann/kdtree_single_index.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,19 @@ class KDTreeSingleIndex : public NNIndex<Distance>
548548
/* If this is a leaf node, then do check and return. */
549549
if ((node->child1 == NULL)&&(node->child2 == NULL)) {
550550
DistanceType worst_dist = result_set.worstDist();
551-
for (int i=node->left; i<node->right; ++i) {
552-
int index = reorder_ ? i : vind_[i];
553-
DistanceType dist = distance_(vec, data_[index], dim_, worst_dist);
554-
if (dist<worst_dist) {
555-
result_set.addPoint(dist,vind_[i]);
551+
if (reorder_) {
552+
for (int i=node->left; i<node->right; ++i) {
553+
DistanceType dist = distance_(vec, data_[i], dim_, worst_dist);
554+
if (dist<worst_dist) {
555+
result_set.addPoint(dist,vind_[i]);
556+
}
557+
}
558+
} else {
559+
for (int i=node->left; i<node->right; ++i) {
560+
DistanceType dist = distance_(vec, data_[vind_[i]], dim_, worst_dist);
561+
if (dist<worst_dist) {
562+
result_set.addPoint(dist,vind_[i]);
563+
}
556564
}
557565
}
558566
return;

0 commit comments

Comments
 (0)