From: Arnaud Giersch Date: Wed, 25 Nov 2020 12:05:12 +0000 (+0100) Subject: A binary search can be used here too. X-Git-Tag: v3.26~116 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d99be9bd356f170d3dff23a52725d65df20186bb A binary search can be used here too. --- diff --git a/src/mc/inspect/ObjectInformation.cpp b/src/mc/inspect/ObjectInformation.cpp index 236a35b268..aefd471b35 100644 --- a/src/mc/inspect/ObjectInformation.cpp +++ b/src/mc/inspect/ObjectInformation.cpp @@ -64,13 +64,11 @@ Frame* ObjectInformation::find_function(const void* ip) const : nullptr; } -const Variable* ObjectInformation::find_variable(const char* name) const +const Variable* ObjectInformation::find_variable(const char* var_name) const { - for (Variable const& variable : this->global_variables) { - if (variable.name == name) - return &variable; - } - return nullptr; + auto pos = std::lower_bound(this->global_variables.begin(), this->global_variables.end(), var_name, + [](auto const& var, const char* name) { return var.name < name; }); + return (pos != this->global_variables.end() && pos->name == var_name) ? &(*pos) : nullptr; } void ObjectInformation::remove_global_variable(const char* var_name)