Skip to content

Commit e45d74c

Browse files
committed
Merge pull request opencv#17638 from pemmanuelviel:pev--avoid-branching-in-loop
2 parents 923009b + 29f883f commit e45d74c

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)