Don't search the entire type table just to delete a type by name.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 6 Aug 2009 06:04:35 +0000 (06:04 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 6 Aug 2009 06:04:35 +0000 (06:04 +0000)
 - This also fixes the ENABLE_EXPENSIVE_CHECKS failure on vmcore.ml.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78287 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/TypeSymbolTable.h
lib/VMCore/Core.cpp
lib/VMCore/TypeSymbolTable.cpp

index d00c3b8d0b4586a17ddcadc1a8215d60a84aabd8..4dd3a4af2a4871cdde8fa62e4366861df43040ac 100644 (file)
@@ -66,6 +66,16 @@ public:
   /// @brief Lookup a type by name.
   Type *lookup(const StringRef &name) const;
 
+  /// Lookup the type associated with name.
+  /// @returns end() if the name is not found, or an iterator at the entry for
+  /// Type.
+  iterator find(const StringRef &name);
+
+  /// Lookup the type associated with name.
+  /// @returns end() if the name is not found, or an iterator at the entry for
+  /// Type.
+  const_iterator find(const StringRef &name) const;
+
   /// @returns true iff the symbol table is empty.
   /// @brief Determine if the symbol table is empty
   inline bool empty() const { return tmap.empty(); }
index 6cce6782eea8aa1837bfae0c856de15f9506ff2c..88160e162976ea14147ce6f2cda98d8304ff6083 100644 (file)
@@ -94,17 +94,15 @@ int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
 }
 
 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name) {
-  std::string N(Name);
-  
   TypeSymbolTable &TST = unwrap(M)->getTypeSymbolTable();
-  for (TypeSymbolTable::iterator I = TST.begin(), E = TST.end(); I != E; ++I)
-    if (I->first == N)
-      TST.remove(I);
+
+  TypeSymbolTable::iterator I = TST.find(Name);
+  if (I != TST.end())
+    TST.remove(I);
 }
 
 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
-  std::string N(Name);
-  return wrap(unwrap(M)->getTypeByName(N));
+  return wrap(unwrap(M)->getTypeByName(Name));
 }
 
 void LLVMDumpModule(LLVMModuleRef M) {
index e9c62559332f12ad62dbdbc2b819753c859e46dc..5fa8785eeb9dd1438cba918797fefe1330de3c86 100644 (file)
@@ -59,6 +59,17 @@ Type* TypeSymbolTable::lookup(const StringRef &Name) const {
   return result;
 }
 
+TypeSymbolTable::iterator TypeSymbolTable::find(const StringRef &Name) {
+  sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);  
+  return tmap.find(Name);
+}
+
+TypeSymbolTable::const_iterator
+TypeSymbolTable::find(const StringRef &Name) const {
+  sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);  
+  return tmap.find(Name);
+}
+
 // remove - Remove a type from the symbol table...
 Type* TypeSymbolTable::remove(iterator Entry) {
   TypeSymbolTableLock->writer_acquire();