summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-21 00:18:40 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-21 00:18:40 +0000
commit5f989abcd447bfa843dfb217dcf087f7e9d8d008 (patch)
tree261f2619984688e9bdf6963ad559fe3cbf3c3860
parent6572faa1ebec3b6f25eda4e8fd07d5f224e2a0af (diff)
downloadbcm5719-llvm-5f989abcd447bfa843dfb217dcf087f7e9d8d008.tar.gz
bcm5719-llvm-5f989abcd447bfa843dfb217dcf087f7e9d8d008.zip
AsmParser: Use StringRef for keyword comparisons, NFC
Leverage `StringRef` inside keyword comparison macros. There's no reason to be so low-level here, and I'm about to add another `startswith()` use, so let's make it easy to read. llvm-svn: 230100
-rw-r--r--llvm/lib/AsmParser/LLLexer.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 7e0f92f3a9b..656b1692182 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -486,11 +486,11 @@ lltok::Kind LLLexer::LexIdentifier() {
if (!KeywordEnd) KeywordEnd = CurPtr;
CurPtr = KeywordEnd;
--StartChar;
- unsigned Len = CurPtr-StartChar;
-#define KEYWORD(STR) \
- do { \
- if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
- return lltok::kw_##STR; \
+ StringRef Keyword(StartChar, CurPtr - StartChar);
+#define KEYWORD(STR) \
+ do { \
+ if (Keyword == #STR) \
+ return lltok::kw_##STR; \
} while (0)
KEYWORD(true); KEYWORD(false);
@@ -670,7 +670,7 @@ lltok::Kind LLLexer::LexIdentifier() {
// Keywords for types.
#define TYPEKEYWORD(STR, LLVMTY) \
do { \
- if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
+ if (Keyword == STR) { \
TyVal = LLVMTY; \
return lltok::Type; \
} \
@@ -690,7 +690,7 @@ lltok::Kind LLLexer::LexIdentifier() {
// Keywords for instructions.
#define INSTKEYWORD(STR, Enum) \
do { \
- if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
+ if (Keyword == #STR) { \
UIntVal = Instruction::Enum; \
return lltok::kw_##STR; \
} \
@@ -748,9 +748,8 @@ lltok::Kind LLLexer::LexIdentifier() {
#define DWKEYWORD(TYPE, TOKEN) \
do { \
- if (Len >= strlen("DW_" #TYPE "_") && \
- !memcmp(StartChar, "DW_" #TYPE "_", strlen("DW_" #TYPE "_"))) { \
- StrVal.assign(StartChar, CurPtr); \
+ if (Keyword.startswith("DW_" #TYPE "_")) { \
+ StrVal.assign(Keyword.begin(), Keyword.end()); \
return lltok::TOKEN; \
} \
} while (false)
OpenPOWER on IntegriCloud