-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use sort_by_cached_key when the key function is not trivial/free #55821
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,7 +409,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { | |
.collect::<Vec<_>>(); | ||
|
||
// existential predicates need to be in a specific order | ||
associated_types.sort_by_key(|item| self.def_path_hash(item.def_id)); | ||
associated_types.sort_by_cached_key(|item| self.def_path_hash(item.def_id)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, of course |
||
|
||
let projection_predicates = associated_types.into_iter().map(|item| { | ||
ty::ExistentialPredicate::Projection(ty::ExistentialProjection { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -985,7 +985,7 @@ fn collect_and_partition_mono_items<'a, 'tcx>( | |
output.push_str(" @@"); | ||
let mut empty = Vec::new(); | ||
let cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty); | ||
cgus.as_mut_slice().sort_by_key(|&(ref name, _)| name.clone()); | ||
cgus.as_mut_slice().sort_by_cached_key(|&(ref name, _)| name.clone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might make sense. Not sure what type |
||
cgus.dedup(); | ||
for &(ref cgu_name, (linkage, _)) in cgus.iter() { | ||
output.push_str(" "); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you noted, I think this is already cached -- it's something we do a lot in incremental. You agree, @michaelwoerister ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's cached, yes, but still not entirely trivial. I.e. it has to do the local/upstream crate dispatch and for upstream
DefIds
it has to go through a number of function calls:rust/src/librustc/ty/context.rs
Line 1325 in 780658a
So, I can imagine this being a win for sorting where each key might be compared against multiple times.