From 03db640132f85c540ad9c0278687e8235abc01e0 Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Sun, 13 May 2018 03:38:07 +0300 Subject: [PATCH] #0 [Core] findRange() fix for writeTreesToStream() --- easy_profiler_core/writer.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/easy_profiler_core/writer.cpp b/easy_profiler_core/writer.cpp index b85fe4a..11a616d 100644 --- a/easy_profiler_core/writer.cpp +++ b/easy_profiler_core/writer.cpp @@ -138,21 +138,29 @@ static BlocksRange findRange(const profiler::BlocksTree::children_t& children, p const auto size = static_cast(children.size()); BlocksRange range(size); - auto first_it = std::lower_bound(children.begin(), children.end(), beginTime, [&](profiler::block_index_t element, profiler::timestamp_t value) + if (size == 0) + return range; + + if (beginTime <= getter(children.front()).node->begin() && getter(children.back()).node->end() <= endTime) + return range; // All blocks inside range + + auto first_it = std::lower_bound(children.begin(), children.end(), beginTime, + [&](profiler::block_index_t element, profiler::timestamp_t value) { return getter(element).node->end() < value; }); - for (auto it = first_it; it != children.end(); ++it) + for (; first_it != children.end(); ++first_it) { - const auto& child = getter(*it); + const auto& child = getter(*first_it); if (child.node->begin() >= beginTime || child.node->end() > beginTime) break; } if (first_it != children.end() && getter(*first_it).node->begin() <= endTime) { - auto last_it = std::lower_bound(children.begin(), children.end(), endTime, [&](profiler::block_index_t element, profiler::timestamp_t value) + auto last_it = std::lower_bound(children.begin(), children.end(), endTime, + [&](profiler::block_index_t element, profiler::timestamp_t value) { return getter(element).node->begin() <= value; });