-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Inline most of the code paths for conversions with boxed slices #49555
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -583,7 +583,9 @@ impl<T> Vec<T> { | |
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub fn shrink_to_fit(&mut self) { | ||
self.buf.shrink_to_fit(self.len); | ||
if self.capacity() != self.len { | ||
self.buf.shrink_to_fit(self.len); | ||
} | ||
} | ||
|
||
/// Shrinks the capacity of the vector with a lower bound. | ||
|
@@ -636,6 +638,7 @@ impl<T> Vec<T> { | |
/// assert_eq!(slice.into_vec().capacity(), 3); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[inline(always)] | ||
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. OTOH, removing this one makes the 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. Hm so in general 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. Sure! #![crate_type = "lib"]
#[no_mangle]
pub fn foo() -> Box<[u8]> {
vec![0].into_boxed_slice()
}
#[no_mangle]
pub fn bar() -> Box<[u8]> {
vec![0].into_boxed_slice()
} 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. Hm ok I'm tempted though to leave this as-is and let LLVM decide these sorts of things, we've had bad experiences in the past optimizing too much for microbenchmarks unfortunately 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. Did you mean this specific 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. Oh just this one particular instance of the attribute. The function is generic so it's already candidate to be inlined everywhere, and it sounds like |
||
pub fn into_boxed_slice(mut self) -> Box<[T]> { | ||
unsafe { | ||
self.shrink_to_fit(); | ||
|
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 think that these don't need the
#[inline]
attribute because they're already generic, right?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'll check and report back.
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.
Indeed, this wasn't necessary. I removed it and compiled a module with
foo
duplicated, here is the result of compiling that to assembly: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.
Was the code change here also still necessary to get the same size reductions?