mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-25 00:29:20 +00:00
Replace a hand-written suffix compare with std::lexicographical_compare.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218380 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
10cd8098a7
commit
7a27231780
@ -12,25 +12,17 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
static bool compareBySuffix(StringRef a, StringRef b) {
|
||||
size_t sizeA = a.size();
|
||||
size_t sizeB = b.size();
|
||||
size_t len = std::min(sizeA, sizeB);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
char ca = a[sizeA - i - 1];
|
||||
char cb = b[sizeB - i - 1];
|
||||
if (ca != cb)
|
||||
return ca > cb;
|
||||
}
|
||||
return sizeA > sizeB;
|
||||
}
|
||||
|
||||
void StringTableBuilder::finalize() {
|
||||
SmallVector<StringRef, 8> Strings;
|
||||
for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i)
|
||||
Strings.push_back(i->getKey());
|
||||
|
||||
std::sort(Strings.begin(), Strings.end(), compareBySuffix);
|
||||
// Sort the vector so a string is sorted above its suffixes.
|
||||
std::sort(Strings.begin(), Strings.end(), [](StringRef A, StringRef B) {
|
||||
typedef std::reverse_iterator<StringRef::iterator> Reverse;
|
||||
return !std::lexicographical_compare(Reverse(A.end()), Reverse(A.begin()),
|
||||
Reverse(B.end()), Reverse(B.begin()));
|
||||
});
|
||||
|
||||
// FIXME: Starting with a null byte is ELF specific. Generalize this so we
|
||||
// can use the class with other object formats.
|
||||
|
Loading…
Reference in New Issue
Block a user