Skip to content

Commit a190264

Browse files
committed
Minor performance improvements (See discussion on [#271](#271))
1 parent ac1c730 commit a190264

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

include/nanoflann.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,7 @@ class KDTreeSingleIndexAdaptor
17631763
stack.pop();
17641764

17651765
// If this is a leaf node, then do check and return.
1766-
// If they are equal, both pointers are nullptr.
1767-
if (node->child1 == node->child2)
1766+
if (!node->child1) // (if one node is nullptr, both are)
17681767
{
17691768
for (Offset i = node->node_type.lr.left;
17701769
i < node->node_type.lr.right; ++i)
@@ -1963,17 +1962,15 @@ class KDTreeSingleIndexAdaptor
19631962
const float epsError) const
19641963
{
19651964
// If this is a leaf node, then do check and return.
1966-
// If they are equal, both pointers are nullptr.
1967-
if (node->child1 == node->child2)
1965+
if (!node->child1) // (if one node is nullptr, both are)
19681966
{
1969-
DistanceType worst_dist = result_set.worstDist();
19701967
for (Offset i = node->node_type.lr.left;
19711968
i < node->node_type.lr.right; ++i)
19721969
{
19731970
const IndexType accessor = Base::vAcc_[i]; // reorder... : i;
19741971
DistanceType dist = distance_.evalMetric(
19751972
vec, accessor, (DIM > 0 ? DIM : Base::dim_));
1976-
if (dist < worst_dist)
1973+
if (dist < result_set.worstDist())
19771974
{
19781975
if (!result_set.addPoint(dist, Base::vAcc_[i]))
19791976
{
@@ -2391,18 +2388,16 @@ class KDTreeSingleIndexDynamicAdaptor_
23912388
const float epsError) const
23922389
{
23932390
// If this is a leaf node, then do check and return.
2394-
// If they are equal, both pointers are nullptr.
2395-
if (node->child1 == node->child2)
2391+
if (!node->child1) // (if one node is nullptr, both are)
23962392
{
2397-
DistanceType worst_dist = result_set.worstDist();
23982393
for (Offset i = node->node_type.lr.left;
23992394
i < node->node_type.lr.right; ++i)
24002395
{
24012396
const IndexType index = Base::vAcc_[i]; // reorder... : i;
24022397
if (treeIndex_[index] == -1) continue;
24032398
DistanceType dist = distance_.evalMetric(
24042399
vec, index, (DIM > 0 ? DIM : Base::dim_));
2405-
if (dist < worst_dist)
2400+
if (dist < result_set.worstDist())
24062401
{
24072402
if (!result_set.addPoint(
24082403
static_cast<typename RESULTSET::DistanceType>(dist),

0 commit comments

Comments
 (0)