From 95b849d05d05ae9e55eb839508536d5af314d331 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 10 Dec 2025 15:20:25 -0800 Subject: 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. --- genericrange.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'genericrange.h') 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>& ranges, std::function&)> orderingStrategy) + GenericRangeMap(const vector>& ranges, bn::base::function_ref&)> 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> GetNextValidRange(uint64_t addr, std::function&)> predicate) const + std::optional> GetNextValidRange(uint64_t addr, bn::base::function_ref&)> 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> GetPreviousValidRange(uint64_t addr, std::function&)> predicate) const + std::optional> GetPreviousValidRange(uint64_t addr, bn::base::function_ref&)> predicate) const { auto itr = m_rangeMap.upper_bound(addr); if (itr != m_rangeMap.begin()) -- cgit v1.3.1