[lld] 0890b39 - [ELF] Simplify isValidCIdentifier. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 09:38:20 PST 2021


Author: Fangrui Song
Date: 2021-03-11T09:38:15-08:00
New Revision: 0890b39ee91d0a6f168e8ba56ecabf0498a8f6e1

URL: https://github.com/llvm/llvm-project/commit/0890b39ee91d0a6f168e8ba56ecabf0498a8f6e1
DIFF: https://github.com/llvm/llvm-project/commit/0890b39ee91d0a6f168e8ba56ecabf0498a8f6e1.diff

LOG: [ELF] Simplify isValidCIdentifier. NFC

Added: 
    

Modified: 
    lld/Common/Strings.cpp

Removed: 
    


################################################################################
diff  --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp
index e3148d3d974d..7bf336490dae 100644
--- a/lld/Common/Strings.cpp
+++ b/lld/Common/Strings.cpp
@@ -76,9 +76,8 @@ std::vector<uint8_t> lld::parseHex(StringRef s) {
 
 // Returns true if S is valid as a C language identifier.
 bool lld::isValidCIdentifier(StringRef s) {
-  return !s.empty() && (isAlpha(s[0]) || s[0] == '_') &&
-         std::all_of(s.begin() + 1, s.end(),
-                     [](char c) { return c == '_' || isAlnum(c); });
+  return !s.empty() && !isDigit(s[0]) &&
+         llvm::all_of(s, [](char c) { return isAlnum(c) || c == '_'; });
 }
 
 // Write the contents of the a buffer to a file


        


More information about the llvm-commits mailing list