[Lldb-commits] [PATCH] D63268: Make UniqueCStringMap work with non-default-constructible types and other improvements/cleanups

Greg Clayton via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 13 08:07:43 PDT 2019


clayborg added inline comments.


================
Comment at: include/lldb/Core/UniqueCStringMap.h:87
   T Find(ConstString unique_cstr, T fail_value) const {
-    Entry search_entry(unique_cstr);
-    const_iterator end = m_map.end();
-    const_iterator pos = std::lower_bound(m_map.begin(), end, search_entry);
-    if (pos != end) {
-      if (pos->cstring == unique_cstr)
-        return pos->value;
-    }
+    auto pos = llvm::lower_bound(m_map, unique_cstr, Compare());
+    if (pos != m_map.end() && pos->cstring == unique_cstr)
----------------
What benefits does llvm::lower_bound offer here? With std::lower_bound and std::upper_bound you can write a comparison static functions that take a "const T &" on one side and a ConstString on the other. Lower bound will use one flavor ("static bool operator <(const T&, ConstString);") and upper_bound will use the other ("static bool operator <(ConstString, const T&);"). No need to specify a Compare() object. So the code would be:
```
T Find(ConstString unique_cstr, T fail_value) const {
  const_iterator end = m_map.end();
  const_iterator pos = std::lower_bound(m_map.begin(), end, unique_cstr);
  if (pos != end && pos->cstring == unique_cstr)
    return pos->value;
  return fail_value;
}
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63268/new/

https://reviews.llvm.org/D63268





More information about the lldb-commits mailing list