diff options
author | Craig Topper <craig.topper@sifive.com> | 2024-05-01 14:51:52 -0700 |
---|---|---|
committer | Craig Topper <craig.topper@sifive.com> | 2024-05-01 14:56:56 -0700 |
commit | 500dda049ea1b140a888f284b3c512cd77af6fce (patch) | |
tree | ad2a42306891578259aa99618d490586bdceff70 | |
parent | a7e07988549c79d9bfecec3e630141fff61f52f0 (diff) | |
download | llvm-500dda049ea1b140a888f284b3c512cd77af6fce.zip llvm-500dda049ea1b140a888f284b3c512cd77af6fce.tar.gz llvm-500dda049ea1b140a888f284b3c512cd77af6fce.tar.bz2 |
[RISCV] Refactor version major version parsing in parseNormalizedArchString. NFC
Use an index variable and array indexing instead of manipulating
a temporary StringRef.
-rw-r--r-- | llvm/lib/TargetParser/RISCVISAInfo.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index c763ee7..e8172eb 100644 --- a/llvm/lib/TargetParser/RISCVISAInfo.cpp +++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp @@ -460,19 +460,18 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) { // Split Prefix into the extension name and the major version number // (the trailing digits of Prefix). - int TrailingDigits = 0; - StringRef ExtName = Prefix; - while (!ExtName.empty()) { - if (!isDigit(ExtName.back())) + size_t VersionStart = Prefix.size(); + while (VersionStart != 0) { + if (!isDigit(Prefix[VersionStart - 1])) break; - ExtName = ExtName.drop_back(1); - TrailingDigits++; + --VersionStart; } - if (!TrailingDigits) + if (VersionStart == Prefix.size()) return createStringError(errc::invalid_argument, "extension lacks version in expected format"); - StringRef MajorVersionStr = Prefix.take_back(TrailingDigits); + StringRef ExtName = Prefix.slice(0, VersionStart); + StringRef MajorVersionStr = Prefix.slice(VersionStart, StringRef::npos); if (MajorVersionStr.getAsInteger(10, MajorVersion)) return createStringError(errc::invalid_argument, "failed to parse major version number"); |