diff options
| author | Mark Rowe <mark@vector35.com> | 2025-12-10 15:20:25 -0800 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2025-12-15 20:25:23 -0800 |
| commit | 95b849d05d05ae9e55eb839508536d5af314d331 (patch) | |
| tree | f06fc6ea5c13cc4972fe8b9fdd5c30d94779b045 /genericrange.h | |
| parent | 2f1150703636b2b06d84bb66853fce7382bf6f29 (diff) | |
Use bn::base::function_ref instead of std::function for parameters that are not stored
This avoids the overhead of constructing a `std::function`, which may
require a heap allocation, when calling functions that immediately
invokes a function object.
Diffstat (limited to 'genericrange.h')
| -rw-r--r-- | genericrange.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/genericrange.h b/genericrange.h index 91854d16..413955a8 100644 --- a/genericrange.h +++ b/genericrange.h @@ -21,6 +21,8 @@ #pragma once +#include "base/function_ref.h" + #ifdef BINARYNINJACORE_LIBRARY #include "binaryninjacore_global.h" namespace BinaryNinjaCore @@ -157,16 +159,13 @@ using namespace std; populateRangeMap(); } - GenericRangeMap(const vector<GenericRange<T>>& ranges, std::function<void(vector<T>&)> orderingStrategy) + GenericRangeMap(const vector<GenericRange<T>>& ranges, bn::base::function_ref<void(vector<T>&)> orderingStrategy) { m_sourceRanges = ranges; m_flattenedRanges = ranges; flatten(m_flattenedRanges); - if (orderingStrategy) - { - for (auto& i : m_flattenedRanges) - orderingStrategy(i.GetMutableItems()); - } + for (auto& i : m_flattenedRanges) + orderingStrategy(i.GetMutableItems()); populateRangeMap(); } @@ -206,7 +205,7 @@ using namespace std; throw std::out_of_range("GenericRangeMap::GetMutableGenericRangeAt - Address not found in any range!"); } - std::optional<std::pair<uint64_t, uint64_t>> GetNextValidRange(uint64_t addr, std::function<bool(const GenericRange<T>&)> predicate) const + std::optional<std::pair<uint64_t, uint64_t>> GetNextValidRange(uint64_t addr, bn::base::function_ref<bool(const GenericRange<T>&)> predicate) const { auto itr = m_rangeMap.upper_bound(addr); if (itr != m_rangeMap.begin()) @@ -222,7 +221,7 @@ using namespace std; return std::nullopt; } - std::optional<std::pair<uint64_t, uint64_t>> GetPreviousValidRange(uint64_t addr, std::function<bool(const GenericRange<T>&)> predicate) const + std::optional<std::pair<uint64_t, uint64_t>> GetPreviousValidRange(uint64_t addr, bn::base::function_ref<bool(const GenericRange<T>&)> predicate) const { auto itr = m_rangeMap.upper_bound(addr); if (itr != m_rangeMap.begin()) |
