Add a new version of Module::getFunction that takes a const char* instead
authorChris Lattner <sabre@nondot.org>
Fri, 27 Jun 2008 21:09:10 +0000 (21:09 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 27 Jun 2008 21:09:10 +0000 (21:09 +0000)
of a std::string.  This avoids copying the string to the heap in common
cases.  Patch by Pratik Solanki!

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

include/llvm/Module.h
include/llvm/ValueSymbolTable.h
lib/VMCore/Module.cpp
lib/VMCore/ValueSymbolTable.cpp

index bce671ddb296b378065191badf44ad8214bb10b2..56207a0af27f35f8e3612be8e17f30ccdf1c3f61 100644 (file)
@@ -209,6 +209,7 @@ public:
   /// getFunction - Look up the specified function in the module symbol table.
   /// If it does not exist, return null.
   Function *getFunction(const std::string &Name) const;
+  Function *getFunction(const char *Name) const;
 
 /// @}
 /// @name Global Variable Accessors
index 54522df6a15b083b6c83d82e2b3b1b5c6bfaa690..6f79f6f393af067c51e550933e9ba00165e99a77 100644 (file)
@@ -67,6 +67,7 @@ public:
   /// @returns the value associated with the \p name
   /// @brief Lookup a named Value.
   Value *lookup(const std::string &name) const;
+  Value *lookup(const char *NameBegin, const char *NameEnd) const;
 
   /// @returns true iff the symbol table is empty
   /// @brief Determine if the symbol table is empty
index 429cf1a4c69508066e17a9f8569a22ce7a21871e..893a5fdcb00d640a5f52b288a8ce4b45688f04a5 100644 (file)
@@ -201,6 +201,11 @@ Function *Module::getFunction(const std::string &Name) const {
   return dyn_cast_or_null<Function>(SymTab.lookup(Name));
 }
 
+Function *Module::getFunction(const char *Name) const {
+  const ValueSymbolTable &SymTab = getValueSymbolTable();
+  return dyn_cast_or_null<Function>(SymTab.lookup(Name, Name+strlen(Name)));
+}
+
 //===----------------------------------------------------------------------===//
 // Methods for easy access to the global variables in the module.
 //
index fb7c0d8509b9b22f17077d6fba1a8c27f415e8ca..f527863e1b5d8fd563c9ad34ed857cb303109f59 100644 (file)
@@ -54,6 +54,14 @@ Value *ValueSymbolTable::lookup(const std::string &Name) const {
   return 0;
 }
 
+Value *ValueSymbolTable::lookup(const char *NameBegin,
+                                const char *NameEnd) const {
+  const_iterator VI = vmap.find(NameBegin, NameEnd);
+  if (VI != vmap.end())                   // We found the symbol
+    return VI->getValue();
+  return 0;
+}
+
 // Insert a value into the symbol table with the specified name...
 //
 void ValueSymbolTable::reinsertValue(Value* V) {