|
18 | 18 | #include "clang/Basic/TargetInfo.h" |
19 | 19 |
|
20 | 20 | #include "llvm/ADT/StringMap.h" |
| 21 | +#include "llvm/ADT/StringSwitch.h" |
21 | 22 |
|
22 | 23 | using namespace clang; |
23 | 24 |
|
@@ -155,26 +156,17 @@ std::string AttributeCommonInfo::getNormalizedFullName() const { |
155 | 156 | normalizeName(getAttrName(), getScopeName(), getSyntax())); |
156 | 157 | } |
157 | 158 |
|
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 | | - |
169 | 159 | AttributeCommonInfo::Scope |
170 | 160 | 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); |
178 | 170 | } |
179 | 171 |
|
180 | 172 | unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const { |
|
0 commit comments