Skip to content

Commit dbad941

Browse files
authored
[NFC][Clang] Use StringSwitch instead of array for parsing attribute scope (llvm#115414)
1 parent 552f6fe commit dbad941

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

clang/lib/Basic/Attributes.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/TargetInfo.h"
1919

2020
#include "llvm/ADT/StringMap.h"
21+
#include "llvm/ADT/StringSwitch.h"
2122

2223
using namespace clang;
2324

@@ -155,26 +156,17 @@ std::string AttributeCommonInfo::getNormalizedFullName() const {
155156
normalizeName(getAttrName(), getScopeName(), getSyntax()));
156157
}
157158

158-
// Sorted list of attribute scope names
159-
static constexpr std::pair<StringRef, AttributeCommonInfo::Scope> ScopeList[] =
160-
{{"", AttributeCommonInfo::Scope::NONE},
161-
{"clang", AttributeCommonInfo::Scope::CLANG},
162-
{"gnu", AttributeCommonInfo::Scope::GNU},
163-
{"gsl", AttributeCommonInfo::Scope::GSL},
164-
{"hlsl", AttributeCommonInfo::Scope::HLSL},
165-
{"msvc", AttributeCommonInfo::Scope::MSVC},
166-
{"omp", AttributeCommonInfo::Scope::OMP},
167-
{"riscv", AttributeCommonInfo::Scope::RISCV}};
168-
169159
AttributeCommonInfo::Scope
170160
getScopeFromNormalizedScopeName(StringRef ScopeName) {
171-
auto It = std::lower_bound(
172-
std::begin(ScopeList), std::end(ScopeList), ScopeName,
173-
[](const std::pair<StringRef, AttributeCommonInfo::Scope> &Element,
174-
StringRef Value) { return Element.first < Value; });
175-
assert(It != std::end(ScopeList) && It->first == ScopeName);
176-
177-
return It->second;
161+
return llvm::StringSwitch<AttributeCommonInfo::Scope>(ScopeName)
162+
.Case("", AttributeCommonInfo::Scope::NONE)
163+
.Case("clang", AttributeCommonInfo::Scope::CLANG)
164+
.Case("gnu", AttributeCommonInfo::Scope::GNU)
165+
.Case("gsl", AttributeCommonInfo::Scope::GSL)
166+
.Case("hlsl", AttributeCommonInfo::Scope::HLSL)
167+
.Case("msvc", AttributeCommonInfo::Scope::MSVC)
168+
.Case("omp", AttributeCommonInfo::Scope::OMP)
169+
.Case("riscv", AttributeCommonInfo::Scope::RISCV);
178170
}
179171

180172
unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {

0 commit comments

Comments
 (0)