|
13 | 13 | html_root_url = "https://doc.rust-lang.org/nightly/")]
|
14 | 14 |
|
15 | 15 | #![feature(rustc_diagnostic_macros)]
|
| 16 | +#![feature(slice_sort_by_cached_key)] |
16 | 17 |
|
17 | 18 | #[macro_use]
|
18 | 19 | extern crate log;
|
@@ -1149,13 +1150,9 @@ impl<'a> ModuleData<'a> {
|
1149 | 1150 |
|
1150 | 1151 | fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
|
1151 | 1152 | let resolutions = self.resolutions.borrow();
|
1152 |
| - let mut resolutions = resolutions.iter().map(|(&(ident, ns), &resolution)| { |
1153 |
| - // Pre-compute keys for sorting |
1154 |
| - (ident.name.as_str(), ns, ident, resolution) |
1155 |
| - }) |
1156 |
| - .collect::<Vec<_>>(); |
1157 |
| - resolutions.sort_unstable_by_key(|&(str, ns, ..)| (str, ns)); |
1158 |
| - for &(_, ns, ident, resolution) in resolutions.iter() { |
| 1153 | + let mut resolutions = resolutions.iter().collect::<Vec<_>>(); |
| 1154 | + resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.name.as_str(), ns)); |
| 1155 | + for &(&(ident, ns), &resolution) in resolutions.iter() { |
1159 | 1156 | resolution.borrow().binding.map(|binding| f(ident, ns, binding));
|
1160 | 1157 | }
|
1161 | 1158 | }
|
@@ -3340,7 +3337,9 @@ impl<'a> Resolver<'a> {
|
3340 | 3337 | let is_mod = |def| match def { Def::Mod(..) => true, _ => false };
|
3341 | 3338 | let mut candidates =
|
3342 | 3339 | self.lookup_import_candidates(name, TypeNS, is_mod);
|
3343 |
| - candidates.sort_by_key(|c| (c.path.segments.len(), c.path.to_string())); |
| 3340 | + candidates.sort_by_cached_key(|c| { |
| 3341 | + (c.path.segments.len(), c.path.to_string()) |
| 3342 | + }); |
3344 | 3343 | if let Some(candidate) = candidates.get(0) {
|
3345 | 3344 | format!("Did you mean `{}`?", candidate.path)
|
3346 | 3345 | } else {
|
@@ -3578,7 +3577,7 @@ impl<'a> Resolver<'a> {
|
3578 | 3577 |
|
3579 | 3578 | let name = path[path.len() - 1].name;
|
3580 | 3579 | // Make sure error reporting is deterministic.
|
3581 |
| - names.sort_by_key(|name| name.as_str()); |
| 3580 | + names.sort_by_cached_key(|name| name.as_str()); |
3582 | 3581 | match find_best_match_for_name(names.iter(), &name.as_str(), None) {
|
3583 | 3582 | Some(found) if found != name => Some(found),
|
3584 | 3583 | _ => None,
|
|
0 commit comments