Use llvm::stable_sort

Make some small adjustment while touching the code: make parameters
const, use less_first(), etc.

Differential Revision: https://reviews.llvm.org/D60989

llvm-svn: 358943
diff --git a/lld/ELF/CallGraphSort.cpp b/lld/ELF/CallGraphSort.cpp
index 10fc6bf..eacaca7 100644
--- a/lld/ELF/CallGraphSort.cpp
+++ b/lld/ELF/CallGraphSort.cpp
@@ -172,8 +172,8 @@
     SecToCluster[I] = &Clusters[I];
   }
 
-  std::stable_sort(SortedSecs.begin(), SortedSecs.end(), [&](int A, int B) {
-    return Clusters[B].getDensity() < Clusters[A].getDensity();
+  llvm::stable_sort(SortedSecs, [&](int A, int B) {
+    return Clusters[A].getDensity() > Clusters[B].getDensity();
   });
 
   for (int SI : SortedSecs) {
@@ -209,10 +209,9 @@
   });
 
   // Sort by density.
-  std::stable_sort(Clusters.begin(), Clusters.end(),
-                   [](const Cluster &A, const Cluster &B) {
-                     return A.getDensity() > B.getDensity();
-                   });
+  llvm::stable_sort(Clusters, [](const Cluster &A, const Cluster &B) {
+    return A.getDensity() > B.getDensity();
+  });
 }
 
 DenseMap<const InputSectionBase *, int> CallGraphSort::run() {