Skip to content

Commit

Permalink
[tblgen] Compare const char * with strcmp instead of creating StringRef.
Browse files Browse the repository at this point in the history
Avoids a call to strlen on both strings which always reads the entire
string. strcmp can use early exit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276737 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Jul 26, 2016
1 parent 38a44a8 commit ae09a87
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils/TableGen/SearchableTableEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void SearchableTableEmitter::emitLookupFunction(StringRef Name, StringRef Field,
} else {
// Make sure the result is null terminated because it's going via "char *".
OS << " std::string CanonicalVal = " << Field << ".upper();\n";
OS << " " << PairType << " Val = {CanonicalVal.data(), 0};\n";
OS << " " << PairType << " Val = {CanonicalVal.c_str(), 0};\n";
}

OS << " ArrayRef<" << PairType << "> Table(" << Name << "sBy" << Field
Expand All @@ -206,7 +206,7 @@ void SearchableTableEmitter::emitLookupFunction(StringRef Name, StringRef Field,
OS << ",\n ";
OS << "[](const " << PairType << " &LHS, const " << PairType
<< " &RHS) {\n";
OS << " return StringRef(LHS.first) < StringRef(RHS.first);\n";
OS << " return std::strcmp(LHS.first, RHS.first) < 0;\n";
OS << " });\n\n";
}

Expand Down

0 comments on commit ae09a87

Please sign in to comment.