From d3d620b33df729207805685f6671e1d15cd5b23a Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Wed, 24 Sep 2014 20:37:14 +0000 Subject: [PATCH] Revert r218380. This was breaking Apple internal build bots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218409 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/StringTableBuilder.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/MC/StringTableBuilder.cpp b/lib/MC/StringTableBuilder.cpp index 2343845ee32..db58ece5c86 100644 --- a/lib/MC/StringTableBuilder.cpp +++ b/lib/MC/StringTableBuilder.cpp @@ -12,17 +12,25 @@ 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 Strings; for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i) Strings.push_back(i->getKey()); - // 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 Reverse; - return !std::lexicographical_compare(Reverse(A.end()), Reverse(A.begin()), - Reverse(B.end()), Reverse(B.begin())); - }); + std::sort(Strings.begin(), Strings.end(), compareBySuffix); // FIXME: Starting with a null byte is ELF specific. Generalize this so we // can use the class with other object formats. -- 2.34.1