Skip to content

Commit 4c92ce9

Browse files
mergify[bot]cferreiragonzemiliocuestaf
authored
Use binary search in 'find_change_nts' (#5997) (#6028)
* Use binary search in 'find_change_nts' (#5997) * Refs #23618: Use binary search in 'find_change_nts' Signed-off-by: cferreiragonz <[email protected]> * Refs #23618: Take into account changes with same sequence number Signed-off-by: cferreiragonz <[email protected]> --------- Signed-off-by: cferreiragonz <[email protected]> (cherry picked from commit 434af1b) # Conflicts: # src/cpp/rtps/history/History.cpp * Resolving conflicts Signed-off-by: Emilio Cuesta <[email protected]> --------- Signed-off-by: Emilio Cuesta <[email protected]> Co-authored-by: Carlos Ferreira González <[email protected]> Co-authored-by: Emilio Cuesta <[email protected]>
1 parent 16510a1 commit 4c92ce9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/cpp/rtps/history/History.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fastdds/dds/log/Log.hpp>
2424
#include <fastdds/rtps/common/CacheChange.h>
2525

26+
#include <rtps/common/ChangeComparison.hpp>
2627
#include <rtps/history/BasicPayloadPool.hpp>
2728
#include <rtps/history/CacheChangePool.h>
2829

@@ -54,11 +55,15 @@ History::const_iterator History::find_change_nts(
5455
return const_iterator();
5556
}
5657

57-
return std::find_if(changesBegin(), changesEnd(), [this, ch](const CacheChange_t* chi)
58-
{
59-
// use the derived classes comparisson criteria for searching
60-
return this->matches_change(chi, ch);
61-
});
58+
// Use binary search to find the first change with the same sequence number
59+
auto lb = std::lower_bound(changesBegin(), changesEnd(), ch, fastdds::rtps::history_order_cmp);
60+
61+
if (lb != changesEnd() && matches_change(*lb, ch))
62+
{
63+
return lb;
64+
}
65+
66+
return changesEnd();
6267
}
6368

6469
bool History::matches_change(

0 commit comments

Comments
 (0)