Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A binary search can be used here too.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 25 Nov 2020 12:05:12 +0000 (13:05 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 25 Nov 2020 12:06:37 +0000 (13:06 +0100)
src/mc/inspect/ObjectInformation.cpp

index 236a35b..aefd471 100644 (file)
@@ -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)