Skip to content

Commit eddd2d0

Browse files
committed
Remove likely macros
1 parent b68cd07 commit eddd2d0

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

flatbush.h

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ SOFTWARE.
8686
#endif
8787
#endif
8888

89-
// Branch prediction hint macros (C++11 compatible)
90-
#if defined(__GNUC__) || defined(__clang__)
91-
#define FLATBUSH_LIKELY(x) __builtin_expect(!!(x), 1)
92-
#define FLATBUSH_UNLIKELY(x) __builtin_expect(!!(x), 0)
93-
#else
94-
#define FLATBUSH_LIKELY(x) (x)
95-
#define FLATBUSH_UNLIKELY(x) (x)
96-
#endif
97-
9889
namespace flatbush {
9990
#ifndef FLATBUSH_SPAN
10091
#include <span>
@@ -1667,20 +1658,20 @@ std::vector<size_t> Flatbush<ArrayType>::searchImpl(const Box<ArrayType>& iBound
16671658
// search through child nodes
16681659
for (size_t wPosition = wNodeIndex; wPosition < wEnd; ++wPosition) {
16691660
// check if node bbox intersects with query bbox
1670-
if (FLATBUSH_UNLIKELY(!detail::boxesIntersect(iBounds, mBoxes[wPosition]))) {
1661+
if (!detail::boxesIntersect(iBounds, mBoxes[wPosition])) {
16711662
continue;
16721663
}
16731664

16741665
const size_t wIndex = getIndex<IsWide>(wPosition);
16751666

1676-
if (FLATBUSH_UNLIKELY(wNodeIndex >= wNumItems)) {
1667+
if (wNodeIndex >= wNumItems) {
16771668
wQueue.push_back(wIndex); // node; add it to the search queue
1678-
} else if (FLATBUSH_LIKELY(!iFilterFn) || iFilterFn(wIndex, mBoxes[wPosition])) {
1669+
} else if (!iFilterFn || iFilterFn(wIndex, mBoxes[wPosition])) {
16791670
wResults.push_back(wIndex); // leaf item
16801671
}
16811672
}
16821673

1683-
if (FLATBUSH_UNLIKELY(wQueue.empty())) {
1674+
if (wQueue.empty()) {
16841675
break;
16851676
}
16861677

@@ -1700,7 +1691,7 @@ std::vector<size_t> Flatbush<ArrayType>::searchImpl(const Box<ArrayType>& iBound
17001691
template <typename ArrayType>
17011692
std::vector<size_t> Flatbush<ArrayType>::search(const Box<ArrayType>& iBounds,
17021693
const FilterCb& iFilterFn) const noexcept {
1703-
if (FLATBUSH_UNLIKELY(!canDoSearch(iBounds))) {
1694+
if (!canDoSearch(iBounds)) {
17041695
return std::vector<size_t>();
17051696
}
17061697

@@ -1735,11 +1726,11 @@ std::vector<size_t> Flatbush<ArrayType>::neighborsImpl(const Point<ArrayType>& i
17351726
const size_t wIndex = getIndex<IsWide>(wPosition);
17361727
const auto wDistSquared = detail::computeDistanceSquared(iPoint, mBoxes[wPosition]);
17371728

1738-
if (FLATBUSH_UNLIKELY(wDistSquared > iMaxDistSquared)) {
1729+
if (wDistSquared > iMaxDistSquared) {
17391730
continue;
1740-
} else if (FLATBUSH_UNLIKELY(wNodeIndex >= wNumItems)) {
1731+
} else if (wNodeIndex >= wNumItems) {
17411732
wQueue.emplace(wIndex << 1U, wDistSquared);
1742-
} else if (FLATBUSH_LIKELY(!iFilterFn) || iFilterFn(wIndex, mBoxes[wPosition])) {
1733+
} else if (!iFilterFn || iFilterFn(wIndex, mBoxes[wPosition])) {
17431734
// put an odd index if it's an item rather than a node, to recognize later
17441735
wQueue.emplace((wIndex << 1U) + 1U, wDistSquared); // leaf node
17451736
}
@@ -1749,12 +1740,12 @@ std::vector<size_t> Flatbush<ArrayType>::neighborsImpl(const Point<ArrayType>& i
17491740
while (!wQueue.empty() && (wQueue.top().mId & 1U)) {
17501741
wResults.push_back(wQueue.top().mId >> 1U);
17511742
wQueue.pop();
1752-
if (FLATBUSH_UNLIKELY(wResults.size() >= iMaxResults)) {
1743+
if (wResults.size() >= iMaxResults) {
17531744
return wResults;
17541745
}
17551746
}
17561747

1757-
if (FLATBUSH_UNLIKELY(wQueue.empty())) {
1748+
if (wQueue.empty()) {
17581749
break;
17591750
}
17601751

@@ -1778,7 +1769,7 @@ std::vector<size_t> Flatbush<ArrayType>::neighbors(const Point<ArrayType>& iPoin
17781769
const FilterCb& iFilterFn) const noexcept {
17791770
const auto wMaxDistSquared = iMaxDistance * iMaxDistance;
17801771

1781-
if (FLATBUSH_UNLIKELY(!canDoNeighbors(iPoint, iMaxResults, iMaxDistance, wMaxDistSquared))) {
1772+
if (!canDoNeighbors(iPoint, iMaxResults, iMaxDistance, wMaxDistSquared)) {
17821773
return std::vector<size_t>();
17831774
}
17841775

0 commit comments

Comments
 (0)