From 9177054c04be2c1598c73e28b73d3a033f2fe138 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Oct 2015 15:15:44 +0000 Subject: [PATCH] Use array_pod_sort. NFC. llvm-svn: 251023 --- lib/MC/StringTableBuilder.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/MC/StringTableBuilder.cpp b/lib/MC/StringTableBuilder.cpp index 9de9363611e..86e54471794 100644 --- a/lib/MC/StringTableBuilder.cpp +++ b/lib/MC/StringTableBuilder.cpp @@ -9,12 +9,15 @@ #include "llvm/MC/StringTableBuilder.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/COFF.h" #include "llvm/Support/Endian.h" using namespace llvm; -static bool compareBySuffix(StringRef a, StringRef b) { +static int compareBySuffix(const StringRef *AP, const StringRef *BP) { + StringRef a = *AP; + StringRef b = *BP; size_t sizeA = a.size(); size_t sizeB = b.size(); size_t len = std::min(sizeA, sizeB); @@ -22,9 +25,9 @@ static bool compareBySuffix(StringRef a, StringRef b) { char ca = a[sizeA - i - 1]; char cb = b[sizeB - i - 1]; if (ca != cb) - return ca > cb; + return cb - ca; } - return sizeA > sizeB; + return sizeB - sizeA; } void StringTableBuilder::finalize(Kind kind) { @@ -34,7 +37,7 @@ void StringTableBuilder::finalize(Kind kind) { for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i) Strings.push_back(i->getKey()); - std::sort(Strings.begin(), Strings.end(), compareBySuffix); + array_pod_sort(Strings.begin(), Strings.end(), compareBySuffix); switch (kind) { case ELF: