This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8db229e28771: ObjectFileMachO: Replace std::map with 
llvm::DenseMap (NFC) (authored by aprantl).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D68605?vs=223685&id=223894#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68605

Files:
  lldb/include/lldb/Utility/ConstString.h
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2478,8 +2478,8 @@
   std::vector<uint32_t> N_BRAC_indexes;
   std::vector<uint32_t> N_COMM_indexes;
   typedef std::multimap<uint64_t, uint32_t> ValueToSymbolIndexMap;
-  typedef std::map<uint32_t, uint32_t> NListIndexToSymbolIndexMap;
-  typedef std::map<const char *, uint32_t> ConstNameToSymbolIndexMap;
+  typedef llvm::DenseMap<uint32_t, uint32_t> NListIndexToSymbolIndexMap;
+  typedef llvm::DenseMap<const char *, uint32_t> ConstNameToSymbolIndexMap;
   ValueToSymbolIndexMap N_FUN_addr_to_sym_idx;
   ValueToSymbolIndexMap N_STSYM_addr_to_sym_idx;
   ConstNameToSymbolIndexMap N_GSYM_name_to_sym_idx;
@@ -2689,8 +2689,8 @@
 
             offset = 0;
 
-            typedef std::map<ConstString, uint16_t> UndefinedNameToDescMap;
-            typedef std::map<uint32_t, ConstString> SymbolIndexToName;
+            typedef llvm::DenseMap<ConstString, uint16_t> UndefinedNameToDescMap;
+            typedef llvm::DenseMap<uint32_t, ConstString> SymbolIndexToName;
             UndefinedNameToDescMap undefined_name_to_desc;
             SymbolIndexToName reexport_shlib_needs_fixup;
 
@@ -3487,15 +3487,11 @@
                           // matches, then we can merge the two into just the
                           // function symbol to avoid duplicate entries in
                           // the symbol table
-                          std::pair<ValueToSymbolIndexMap::const_iterator,
-                                    ValueToSymbolIndexMap::const_iterator>
-                              range;
-                          range =
+                          auto range =
                               N_FUN_addr_to_sym_idx.equal_range(nlist.n_value);
                           if (range.first != range.second) {
                             bool found_it = false;
-                            for (ValueToSymbolIndexMap::const_iterator pos =
-                                     range.first;
+                            for (const auto pos = range.first;
                                  pos != range.second; ++pos) {
                               if (sym[sym_idx].GetMangled().GetName(
                                       lldb::eLanguageTypeUnknown,
@@ -3536,15 +3532,11 @@
                           // matches, then we can merge the two into just the
                           // Static symbol to avoid duplicate entries in the
                           // symbol table
-                          std::pair<ValueToSymbolIndexMap::const_iterator,
-                                    ValueToSymbolIndexMap::const_iterator>
-                              range;
-                          range = N_STSYM_addr_to_sym_idx.equal_range(
+                          auto range = N_STSYM_addr_to_sym_idx.equal_range(
                               nlist.n_value);
                           if (range.first != range.second) {
                             bool found_it = false;
-                            for (ValueToSymbolIndexMap::const_iterator pos =
-                                     range.first;
+                            for (const auto pos = range.first;
                                  pos != range.second; ++pos) {
                               if (sym[sym_idx].GetMangled().GetName(
                                       lldb::eLanguageTypeUnknown,
@@ -3667,8 +3659,8 @@
       nlist_idx = 0;
     }
 
-    typedef std::map<ConstString, uint16_t> UndefinedNameToDescMap;
-    typedef std::map<uint32_t, ConstString> SymbolIndexToName;
+    typedef llvm::DenseMap<ConstString, uint16_t> UndefinedNameToDescMap;
+    typedef llvm::DenseMap<uint32_t, ConstString> SymbolIndexToName;
     UndefinedNameToDescMap undefined_name_to_desc;
     SymbolIndexToName reexport_shlib_needs_fixup;
 
Index: lldb/include/lldb/Utility/ConstString.h
===================================================================
--- lldb/include/lldb/Utility/ConstString.h
+++ lldb/include/lldb/Utility/ConstString.h
@@ -10,6 +10,7 @@
 #define liblldb_ConstString_h_
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/Support/FormatVariadic.h"
 
 #include <stddef.h>
@@ -437,6 +438,14 @@
   static size_t StaticMemorySize();
 
 protected:
+  template <typename T> friend struct ::llvm::DenseMapInfo;
+  /// Only used by DenseMapInfo.
+  static ConstString FromStringPoolPointer(const char *ptr) {
+    ConstString s;
+    s.m_string = ptr;
+    return s;
+  };
+
   // Member variables
   const char *m_string;
 };
@@ -451,6 +460,27 @@
   static void format(const lldb_private::ConstString &CS, llvm::raw_ostream &OS,
                      llvm::StringRef Options);
 };
+
+/// DenseMapInfo implementation.
+/// \{
+template <> struct DenseMapInfo<lldb_private::ConstString> {
+  static inline lldb_private::ConstString getEmptyKey() {
+    return lldb_private::ConstString::FromStringPoolPointer(
+        DenseMapInfo<const char *>::getEmptyKey());
+  }
+  static inline lldb_private::ConstString getTombstoneKey() {
+    return lldb_private::ConstString::FromStringPoolPointer(
+        DenseMapInfo<const char *>::getTombstoneKey());
+  }
+  static unsigned getHashValue(lldb_private::ConstString val) {
+    return DenseMapInfo<const char *>::getHashValue(val.m_string);
+  }
+  static bool isEqual(lldb_private::ConstString LHS,
+                      lldb_private::ConstString RHS) {
+    return LHS == RHS;
+  }
+};
+/// \}
 }
 
 #endif // liblldb_ConstString_h_
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to