From 311312ff1fa3f2ec7f62af22003a80018771b546 Mon Sep 17 00:00:00 2001 From: Ziv Shahaf Date: Tue, 19 Dec 2017 11:30:24 +0200 Subject: [PATCH] Performance improvement for lower/upper bound (#1223) * Performance improvement for lower/upper bound Changed updateQueries() to use member functions of `multiset` instead of `std::lower_bound` and `std::upper_bound` * Fixed warnings for C++98 Changed the calls to lower/upper bounds so they dont use the "new" C++11 extended initializer lists. --- tools/rosbag_storage/src/view.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/rosbag_storage/src/view.cpp b/tools/rosbag_storage/src/view.cpp index dbb1e72478..dd9fc4842b 100644 --- a/tools/rosbag_storage/src/view.cpp +++ b/tools/rosbag_storage/src/view.cpp @@ -281,10 +281,11 @@ void View::updateQueries(BagQuery* q) { multiset const& index = j->second; // lower_bound/upper_bound do a binary search to find the appropriate range of Index Entries given our time range - - std::multiset::const_iterator begin = std::lower_bound(index.begin(), index.end(), q->query.getStartTime(), IndexEntryCompare()); - std::multiset::const_iterator end = std::upper_bound(index.begin(), index.end(), q->query.getEndTime(), IndexEntryCompare()); - + IndexEntry start_time_lookup_entry = { q->query.getStartTime(), 0, 0 }; + IndexEntry end_time_lookup_entry = { q->query.getEndTime() , 0, 0 }; + std::multiset::const_iterator begin = index.lower_bound(start_time_lookup_entry); + std::multiset::const_iterator end = index.upper_bound(end_time_lookup_entry); + // Make sure we are at the right beginning while (begin != index.begin() && begin->time >= q->query.getStartTime()) {