-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Improve a few vectors - calculate capacity or build from iterators #52703
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
} | ||
} | ||
let violations = traits::supertrait_def_ids(self, trait_def_id) | ||
.filter(|&def_id| self.predicates_reference_self(def_id, true)) |
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.
I suspect that this one doesn't actually help, since filter gives a lower bound of zero:
Lines 1514 to 1517 in fefe816
fn size_hint(&self) -> (usize, Option<usize>) { | |
let (_, upper) = self.iter.size_hint(); | |
(0, upper) // can't know a lower bound, due to the predicate | |
} |
And thus the collect will be essentially useless at preallocating the Vec:
Lines 1852 to 1853 in fefe816
let (lower, _) = iterator.size_hint(); | |
let mut vector = Vec::with_capacity(lower.saturating_add(1)); |
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.
Fair point; I'd still consider it, though, since it improves readability and is almost a half shorter.
@@ -885,9 +886,9 @@ fn exec_linker(sess: &Session, cmd: &mut Command, out_filename: &Path, tmpdir: & | |||
} | |||
let file = tmpdir.join("linker-arguments"); | |||
let bytes = if sess.target.target.options.is_like_msvc { | |||
let mut out = vec![]; | |||
let mut out = Vec::with_capacity(1 + args.len()); |
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 looks like this will hold the bytes of UTF-16; should it then be 2*args.len
?
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.
Actually it should be (1 + args.len()) * 2
, as each step of the for
loop pushes 2 u8
s. Thanks, I missed that.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Spurious error. |
@kennytm can you trigger a retest pls? |
@ljedrz you could always re-trigger by reopening the PR. |
@kennytm didn't know that, thanks! |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors r+ |
📌 Commit acd38f6 has been approved by |
…akis Improve a few vectors - calculate capacity or build from iterators Collecting from iterators improves readability and tailoring vector capacities should be beneficial in terms of performance.
Rollup of 11 pull requests Successful merges: - #52702 (Suggest fix when encountering different mutability from impl to trait) - #52703 (Improve a few vectors - calculate capacity or build from iterators) - #52740 (Suggest underscore when using dashes in crate namet push fork) - #52759 (Impl Send & Sync for JoinHandle) - #52760 (rustc_metadata: test loading atoi instead of cos) - #52763 (Omit the vendor component in Fuchsia triple) - #52765 (Remove unused "-Zenable_nonzeroing_move_hints" flag) - #52769 (Incorporate a stray test) - #52777 (Fix doc comment for 'ptr::copy_to' method) - #52779 (revert accidental atty downgrade) - #52781 (Use a slice where a vector is not necessary) Failed merges: r? @ghost
Collecting from iterators improves readability and tailoring vector capacities should be beneficial in terms of performance.