summaryrefslogtreecommitdiff
path: root/lib/Target/TargetLibraryInfo.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-03-09 13:48:23 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-03-09 13:48:23 +0000
commit576f62c1ead0c099aacf2bc08552a1348d57c23f (patch)
tree1aad4df5285fe70870363dc8e38d52a4009f94a1 /lib/Target/TargetLibraryInfo.cpp
parente629a33d166f55a916f40a1feae47af8ab97feed (diff)
downloadllvm-576f62c1ead0c099aacf2bc08552a1348d57c23f.tar.gz
llvm-576f62c1ead0c099aacf2bc08552a1348d57c23f.tar.bz2
llvm-576f62c1ead0c099aacf2bc08552a1348d57c23f.tar.xz
TLI: Microoptimize calls to strlen+memcmp to strncmp.
The strlen+memcmp was hidden in a call to StringRef::operator==. We check if there are any null bytes in the string upfront so we can simplify the comparison Small speedup when compiling code with many function calls. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176766 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetLibraryInfo.cpp')
-rw-r--r--lib/Target/TargetLibraryInfo.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Target/TargetLibraryInfo.cpp b/lib/Target/TargetLibraryInfo.cpp
index e5fdce22f4..c6cafe59eb 100644
--- a/lib/Target/TargetLibraryInfo.cpp
+++ b/lib/Target/TargetLibraryInfo.cpp
@@ -597,15 +597,37 @@ TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
CustomNames = TLI.CustomNames;
}
+namespace {
+struct StringComparator {
+ /// Compare two strings and return true if LHS is lexicographically less than
+ /// RHS. Requires that RHS doesn't contain any zero bytes.
+ bool operator()(const char *LHS, StringRef RHS) const {
+ // Compare prefixes with strncmp. If prefixes match we know that LHS is
+ // greater or equal to RHS as RHS can't contain any '\0'.
+ return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;
+ }
+
+ // Provided for compatibility with MSVC's debug mode.
+ bool operator()(StringRef LHS, const char *RHS) const { return LHS < RHS; }
+ bool operator()(StringRef LHS, StringRef RHS) const { return LHS < RHS; }
+};
+}
+
bool TargetLibraryInfo::getLibFunc(StringRef funcName,
LibFunc::Func &F) const {
const char **Start = &StandardNames[0];
const char **End = &StandardNames[LibFunc::NumLibFuncs];
+
+ // Filter out empty names and names containing null bytes, those can't be in
+ // our table.
+ if (funcName.empty() || funcName.find('\0') != StringRef::npos)
+ return false;
+
// Check for \01 prefix that is used to mangle __asm declarations and
// strip it if present.
- if (!funcName.empty() && funcName.front() == '\01')
+ if (funcName.front() == '\01')
funcName = funcName.substr(1);
- const char **I = std::lower_bound(Start, End, funcName);
+ const char **I = std::lower_bound(Start, End, funcName, StringComparator());
if (I != End && *I == funcName) {
F = (LibFunc::Func)(I - Start);
return true;