|
8 | 8 |
|
9 | 9 | #include "llvm/Frontend/Directive/Spelling.h"
|
10 | 10 |
|
11 |
| -#include "llvm/ADT/STLExtras.h" |
12 | 11 | #include "llvm/ADT/StringRef.h"
|
13 | 12 | #include "llvm/Support/MathExtras.h"
|
14 | 13 |
|
15 | 14 | #include <cassert>
|
16 | 15 |
|
| 16 | +static bool Contains(llvm::directive::VersionRange V, int P) { |
| 17 | + return V.Min <= P && P <= V.Max; |
| 18 | +} |
| 19 | + |
17 | 20 | llvm::StringRef llvm::directive::FindName(
|
18 | 21 | llvm::iterator_range<const llvm::directive::Spelling *> Range,
|
19 | 22 | unsigned Version) {
|
20 | 23 | assert(llvm::isInt<8 * sizeof(int)>(Version) && "Version value out of range");
|
21 | 24 |
|
22 | 25 | int V = Version;
|
23 |
| - Spelling Tmp{StringRef(), {V, V}}; |
24 |
| - auto F = |
25 |
| - llvm::lower_bound(Range, Tmp, [](const Spelling &A, const Spelling &B) { |
26 |
| - return A.Versions < B.Versions; |
27 |
| - }); |
28 |
| - if (F != Range.end()) |
29 |
| - return F->Name; |
| 26 | + // Do a linear search to find the first Spelling that contains Version. |
| 27 | + // The condition "contains(S, Version)" does not partition the list of |
| 28 | + // spellings, so std::[lower|upper]_bound cannot be used. |
| 29 | + // In practice the list of spellings is expected to be very short, so |
| 30 | + // linear search seems appropriate. In general, an interval tree may be |
| 31 | + // a better choice, but in this case it may be an overkill. |
| 32 | + for (auto &S : Range) { |
| 33 | + if (Contains(S.Versions, V)) |
| 34 | + return S.Name; |
| 35 | + } |
30 | 36 | return StringRef();
|
31 | 37 | }
|
0 commit comments