From bb0e2487185e401c7fca63d55e59343e060912a2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 27 Jun 2008 21:09:10 +0000 Subject: [PATCH] Add a new version of Module::getFunction that takes a const char* instead 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 | 1 + include/llvm/ValueSymbolTable.h | 1 + lib/VMCore/Module.cpp | 5 +++++ lib/VMCore/ValueSymbolTable.cpp | 8 ++++++++ 4 files changed, 15 insertions(+) diff --git a/include/llvm/Module.h b/include/llvm/Module.h index bce671ddb29..56207a0af27 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -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 diff --git a/include/llvm/ValueSymbolTable.h b/include/llvm/ValueSymbolTable.h index 54522df6a15..6f79f6f393a 100644 --- a/include/llvm/ValueSymbolTable.h +++ b/include/llvm/ValueSymbolTable.h @@ -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 diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 429cf1a4c69..893a5fdcb00 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -201,6 +201,11 @@ Function *Module::getFunction(const std::string &Name) const { return dyn_cast_or_null(SymTab.lookup(Name)); } +Function *Module::getFunction(const char *Name) const { + const ValueSymbolTable &SymTab = getValueSymbolTable(); + return dyn_cast_or_null(SymTab.lookup(Name, Name+strlen(Name))); +} + //===----------------------------------------------------------------------===// // Methods for easy access to the global variables in the module. // diff --git a/lib/VMCore/ValueSymbolTable.cpp b/lib/VMCore/ValueSymbolTable.cpp index fb7c0d8509b..f527863e1b5 100644 --- a/lib/VMCore/ValueSymbolTable.cpp +++ b/lib/VMCore/ValueSymbolTable.cpp @@ -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) { -- 2.34.1