aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-27 21:09:10 +0000
committerChris Lattner <sabre@nondot.org>2008-06-27 21:09:10 +0000
commitbb0e2487185e401c7fca63d55e59343e060912a2 (patch)
treeb6b4f48495081a9a79f79bab892cc0db79f63780 /lib/VMCore
parent25b825b3b848eeb25d49a51f0c78a16db7677465 (diff)
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
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Module.cpp5
-rw-r--r--lib/VMCore/ValueSymbolTable.cpp8
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index 429cf1a4c6..893a5fdcb0 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<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.
//
diff --git a/lib/VMCore/ValueSymbolTable.cpp b/lib/VMCore/ValueSymbolTable.cpp
index fb7c0d8509..f527863e1b 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) {