Skip to content

Commit b520c42

Browse files
committed
Prefer sort_unstable*() over sort*()
1 parent 6a3db03 commit b520c42

File tree

41 files changed

+68
-68
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+68
-68
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4803,6 +4803,6 @@ fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body>) -> Vec<hir::BodyId> {
48034803
// Sorting by span ensures that we get things in order within a
48044804
// file, and also puts the files in a sensible order.
48054805
let mut body_ids: Vec<_> = bodies.keys().cloned().collect();
4806-
body_ids.sort_by_key(|b| bodies[b].value.span);
4806+
body_ids.sort_unstable_by_key(|b| bodies[b].value.span);
48074807
body_ids
48084808
}

src/librustc/hir/pat_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl hir::Pat {
157157
}
158158
true
159159
});
160-
variants.sort();
160+
variants.sort_unstable();
161161
variants.dedup();
162162
variants
163163
}

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
434434
};
435435

436436
// sort the errors by span, for better error message stability.
437-
errors.sort_by_key(|u| match *u {
437+
errors.sort_unstable_by_key(|u| match *u {
438438
RegionResolutionError::ConcreteFailure(ref sro, _, _) => sro.span(),
439439
RegionResolutionError::GenericBoundFailure(ref sro, _, _) => sro.span(),
440440
RegionResolutionError::SubSupConflict(ref rvo, _, _, _, _) => rvo.span(),

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
568568
_ => 2,
569569
}
570570
}
571-
lower_bounds.sort_by_key(region_order_key);
572-
upper_bounds.sort_by_key(region_order_key);
571+
lower_bounds.sort_unstable_by_key(region_order_key);
572+
upper_bounds.sort_unstable_by_key(region_order_key);
573573

574574
for lower_bound in &lower_bounds {
575575
for upper_bound in &upper_bounds {

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14261426
.collect();
14271427

14281428
// ensure that we issue lints in a repeatable order
1429-
def_ids.sort_by_key(|&def_id| self.tcx.def_path_hash(def_id));
1429+
def_ids.sort_unstable_by_key(|&def_id| self.tcx.def_path_hash(def_id));
14301430

14311431
for def_id in def_ids {
14321432
debug!(

src/librustc/session/code_stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl CodeStats {
100100

101101
// Primary sort: large-to-small.
102102
// Secondary sort: description (dictionary order)
103-
sorted.sort_by(|info1, info2| {
103+
sorted.sort_unstable_by(|info1, info2| {
104104
// (reversing cmp order to get large-to-small ordering)
105105
match info2.overall_size.cmp(&info1.overall_size) {
106106
Ordering::Equal => info1.type_description.cmp(&info2.type_description),
@@ -151,7 +151,7 @@ impl CodeStats {
151151

152152
// We want to print fields by increasing offset.
153153
let mut fields = fields.clone();
154-
fields.sort_by_key(|f| f.offset);
154+
fields.sort_unstable_by_key(|f| f.offset);
155155

156156
for field in fields.iter() {
157157
let FieldInfo { ref name, offset, size, align } = *field;

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ mod dep_tracking {
24012401
impl DepTrackingHash for Vec<$t> {
24022402
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
24032403
let mut elems: Vec<&$t> = self.iter().collect();
2404-
elems.sort();
2404+
elems.sort_unstable();
24052405
Hash::hash(&elems.len(), hasher);
24062406
for (index, elem) in elems.iter().enumerate() {
24072407
Hash::hash(&index, hasher);

src/librustc/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
288288
match kind {
289289
StructKind::AlwaysSized |
290290
StructKind::MaybeUnsized => {
291-
optimizing.sort_by_key(|&x| {
291+
optimizing.sort_unstable_by_key(|&x| {
292292
// Place ZSTs first to avoid "interesting offsets",
293293
// especially with only one or two non-ZST fields.
294294
let f = &fields[x as usize];
295295
(!f.is_zst(), cmp::Reverse(field_align(f)))
296296
});
297297
}
298298
StructKind::Prefixed(..) => {
299-
optimizing.sort_by_key(|&x| field_align(&fields[x as usize]));
299+
optimizing.sort_unstable_by_key(|&x| field_align(&fields[x as usize]));
300300
}
301301
}
302302
}

src/librustc/util/time_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl TimeGraph {
127127
let mut threads: Vec<PerThread> =
128128
table.values().map(|data| data.clone()).collect();
129129

130-
threads.sort_by_key(|timeline| timeline.timings[0].start);
130+
threads.sort_unstable_by_key(|timeline| timeline.timings[0].start);
131131

132132
let earliest_instant = threads[0].timings[0].start;
133133
let latest_instant = threads.iter()

src/librustc_codegen_llvm/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ fn start_executing_work(tcx: TyCtxt,
19231923
// Regardless of what order these modules completed in, report them to
19241924
// the backend in the same order every time to ensure that we're handing
19251925
// out deterministic results.
1926-
compiled_modules.sort_by(|a, b| a.name.cmp(&b.name));
1926+
compiled_modules.sort_unstable_by(|a, b| a.name.cmp(&b.name));
19271927

19281928
let compiled_metadata_module = compiled_metadata_module
19291929
.expect("Metadata module not compiled?");

0 commit comments

Comments
 (0)