Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uptyencode: Make sure that projection bounds are handled in stable order. #34805
Conversation
rust-highfive
assigned
alexcrichton
Jul 13, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @eddyb |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
triage: beta-nominated |
rust-highfive
added
the
beta-nominated
label
Jul 13, 2016
alexcrichton
added
the
T-compiler
label
Jul 13, 2016
aravind-pg
reviewed
Jul 13, 2016
| .iter() | ||
| .map(|b| (b.item_name().as_str(), b)) | ||
| .collect(); | ||
| projection_bounds.sort_by_key(|&(ref name, _)| name.clone()); |
This comment has been minimized.
This comment has been minimized.
aravind-pg
Jul 13, 2016
Contributor
Newbie question (and total nit): why couldn't this basically be the following (or something close to it)?
let mut projection_bounds = bs.projection_bounds
.clone()
.sort_by_key(|&b| b.item_name().as_str());Because then it seems we'd be able to keep the next line just for tp in &projection_bounds { ... }, avoiding the extra call to map.
And even if we didn't do this the next line still seems like it could stay for tp in &projection_bounds with s/tp.0/tp.1.0 in the loop body.
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Jul 13, 2016
Author
Contributor
Since sort_by_key() returns nothing, projection_bounds with be the unit value (). It would have to look at least like:
let mut projection_bounds = bs.projection_bounds.clone();
projection_bounds.sort_by_key(|&b| b.item_name().as_str());And why didn't I do it like the above? In order to avoid that b.item_name().as_str() gets called more than once per item. Although, I somehow mistakenly assumed that b.item_name().as_str() would need to hash the string each time when looking it up in the interner, which it doesn't, so this "optimization" is even more premature than I thought :)
So, your version, when fixed as indicated, would actually be nicer than mine.
This comment has been minimized.
This comment has been minimized.
aravind-pg
Jul 13, 2016
Contributor
Ahh, because sort_by_key would make basically O(n log n) calls to its closure, i.e. to b.item_name().as_str()? Makes much more sense now (notwithstanding the question of whether it's a premature optimization :). And yeah I overlooked the fact that sort_by_key returns unit, so your fix makes sense. Thanks for the explanation! Up to you what changes you want to make, if any.
This comment has been minimized.
This comment has been minimized.
|
@bors: p=1 (fixing a regression) |
michaelwoerister commentedJul 13, 2016
Fixes #34796.
r? @alexcrichton