From c4936ff6d2d1149528218de733f8b9647d5590d7 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sat, 21 Nov 2020 13:34:57 -0500 Subject: [PATCH] address review comment --- client/TracyProfiler.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index f796fb1a..8f1b5885 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -2955,24 +2955,19 @@ std::vector ParseMappings() // Internal implementation helper for LookUpMapping(address). // -// Takes as input an `address` and a -// known vector `mappings`, and returns a pointer to the MappingInfo -// describing the mapping that this address belongs to, or nullptr if -// the address isn't in `mappings`. +// Takes as input an `address` and a known vector `mappings`, assumed to be +// sorted by increasing addresses, as /proc/self/maps seems to be. +// Returns a pointer to the MappingInfo describing the mapping that this +// address belongs to, or nullptr if the address isn't in `mappings`. inline MappingInfo* LookUpMapping(std::vector& mappings, uintptr_t address) { - // We assume mappings to be sorted by address, as /proc/self/maps seems to be. - // Construct a MappingInfo just for the purpose of using std::lower_bound. - MappingInfo needle; - needle.start_address = address; - needle.end_address = address; // Comparison function for std::lower_bound. Returns true if all addresses in `m1` - // are lower than all addresses in `m2`. - auto Compare = []( const MappingInfo& m1, const MappingInfo& m2 ) { + // are lower than `addr`. + auto Compare = []( const MappingInfo& m1, uintptr_t addr ) { // '<=' because the address ranges are half-open intervals, [start, end). - return m1.end_address <= m2.start_address; + return m1.end_address <= addr; }; - auto iter = std::lower_bound( mappings.begin(), mappings.end(), needle, Compare ); + auto iter = std::lower_bound( mappings.begin(), mappings.end(), address, Compare ); if( iter == mappings.end() || iter->end_address <= address) { return nullptr; }