[llvm-commits] [llvm] r78287 - in /llvm/trunk: include/llvm/TypeSymbolTable.h lib/VMCore/Core.cpp lib/VMCore/TypeSymbolTable.cpp

Daniel Dunbar daniel at zuster.org
Wed Aug 5 23:04:38 PDT 2009


Author: ddunbar
Date: Thu Aug  6 01:04:35 2009
New Revision: 78287

URL: http://llvm.org/viewvc/llvm-project?rev=78287&view=rev
Log:
Don't search the entire type table just to delete a type by name.
 - This also fixes the ENABLE_EXPENSIVE_CHECKS failure on vmcore.ml.

Modified:
    llvm/trunk/include/llvm/TypeSymbolTable.h
    llvm/trunk/lib/VMCore/Core.cpp
    llvm/trunk/lib/VMCore/TypeSymbolTable.cpp

Modified: llvm/trunk/include/llvm/TypeSymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TypeSymbolTable.h?rev=78287&r1=78286&r2=78287&view=diff

==============================================================================
--- llvm/trunk/include/llvm/TypeSymbolTable.h (original)
+++ llvm/trunk/include/llvm/TypeSymbolTable.h Thu Aug  6 01:04:35 2009
@@ -66,6 +66,16 @@
   /// @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(); }

Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=78287&r1=78286&r2=78287&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Thu Aug  6 01:04:35 2009
@@ -94,17 +94,15 @@
 }
 
 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) {

Modified: llvm/trunk/lib/VMCore/TypeSymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/TypeSymbolTable.cpp?rev=78287&r1=78286&r2=78287&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/TypeSymbolTable.cpp (original)
+++ llvm/trunk/lib/VMCore/TypeSymbolTable.cpp Thu Aug  6 01:04:35 2009
@@ -59,6 +59,17 @@
   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();





More information about the llvm-commits mailing list