Skip to content

Commit cbd8548

Browse files
authored
Merge pull request #57 from odorovskoy/redundant-branch-checks
Eliminate redundant branch checks
2 parents 9870f34 + 39d8f71 commit cbd8548

File tree

1 file changed

+4
-40
lines changed

1 file changed

+4
-40
lines changed

include/interval-tree/interval_tree.hpp

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,20 +1773,12 @@ namespace lib_interval_tree
17731773
}
17741774
if (ptr->left_ && ival.high() <= ptr->left_->max())
17751775
{
1776-
// no right? can only continue left
1777-
if (!ptr->right_ || ival.low() > ptr->right_->max())
1778-
return find_all_i<ThisType, IteratorT>(self, ptr->left_, ival, on_find, compare);
1779-
17801776
if (!find_all_i<ThisType, IteratorT>(self, ptr->left_, ival, on_find, compare))
17811777
return false;
17821778
}
17831779
if (ptr->right_ && ival.high() <= ptr->right_->max())
17841780
{
1785-
if (!ptr->left_ || ival.low() > ptr->left_->max())
1786-
return find_all_i<ThisType, IteratorT>(self, ptr->right_, ival, on_find, compare);
1787-
1788-
if (!find_all_i<ThisType, IteratorT>(self, ptr->right_, ival, on_find, compare))
1789-
return false;
1781+
return find_all_i<ThisType, IteratorT>(self, ptr->right_, ival, on_find, compare);
17901782
}
17911783
return true;
17921784
}
@@ -1807,22 +1799,13 @@ namespace lib_interval_tree
18071799
{
18081800
if (ptr->left_ && ival.high() <= ptr->left_->max())
18091801
{
1810-
// no right? can only continue left
1811-
if (!ptr->right_ || ival.low() > ptr->right_->max())
1812-
return find_i(ptr->left_, ival, compare);
1813-
18141802
auto* res = find_i(ptr->left_, ival, compare);
18151803
if (res != nullptr)
18161804
return res;
18171805
}
18181806
if (ptr->right_ && ival.high() <= ptr->right_->max())
18191807
{
1820-
if (!ptr->left_ || ival.low() > ptr->left_->max())
1821-
return find_i(ptr->right_, ival, compare);
1822-
1823-
auto* res = find_i(ptr->right_, ival, compare);
1824-
if (res != nullptr)
1825-
return res;
1808+
return find_i(ptr->right_, ival, compare);
18261809
}
18271810
return nullptr;
18281811
}
@@ -1884,21 +1867,12 @@ namespace lib_interval_tree
18841867
}
18851868
if (ptr->left_ && ptr->left_->max() >= ival.low())
18861869
{
1887-
// no right? can only continue left
1888-
// or interval low is bigger than max of right branch.
1889-
if (!ptr->right_ || ival.low() > ptr->right_->max())
1890-
return overlap_find_all_i<ThisType, Exclusive, IteratorT>(self, ptr->left_, ival, on_find);
1891-
18921870
if (!overlap_find_all_i<ThisType, Exclusive, IteratorT>(self, ptr->left_, ival, on_find))
18931871
return false;
18941872
}
18951873
if (ptr->right_ && ptr->right_->max() >= ival.low())
18961874
{
1897-
if (!ptr->left_ || ival.low() > ptr->right_->max())
1898-
return overlap_find_all_i<ThisType, Exclusive, IteratorT>(self, ptr->right_, ival, on_find);
1899-
1900-
if (!overlap_find_all_i<ThisType, Exclusive, IteratorT>(self, ptr->right_, ival, on_find))
1901-
return false;
1875+
return overlap_find_all_i<ThisType, Exclusive, IteratorT>(self, ptr->right_, ival, on_find);
19021876
}
19031877
return true;
19041878
}
@@ -1909,23 +1883,13 @@ namespace lib_interval_tree
19091883
{
19101884
if (ptr->left_ && ptr->left_->max() >= ival.low())
19111885
{
1912-
// no right? can only continue left
1913-
// or upper bounds higher than what is contained right? continue left.
1914-
if (!ptr->right_ || ival.low() > ptr->right_->max())
1915-
return overlap_find_i<Exclusive>(ptr->left_, ival);
1916-
19171886
auto* res = overlap_find_i<Exclusive>(ptr->left_, ival);
19181887
if (res != nullptr)
19191888
return res;
19201889
}
19211890
if (ptr->right_ && ptr->right_->max() >= ival.low())
19221891
{
1923-
if (!ptr->left_ || ival.low() > ptr->left_->max())
1924-
return overlap_find_i<Exclusive>(ptr->right_, ival);
1925-
1926-
auto* res = overlap_find_i<Exclusive>(ptr->right_, ival);
1927-
if (res != nullptr)
1928-
return res;
1892+
return overlap_find_i<Exclusive>(ptr->right_, ival);
19291893
}
19301894
return nullptr;
19311895
}

0 commit comments

Comments
 (0)