-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Address &str.slice is bloated #16698
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
Conversation
end, *self); | ||
unsafe { raw::slice_bytes(*self, begin, end) } | ||
assert!(self.is_char_boundary(begin) && self.is_char_boundary(end)) | ||
unsafe { raw::slice_unchecked(*self, begin, end) } |
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.
Could you add comments stating that these are safe due to is_char_boundary
also implicitly checking that the index is in-bounds?
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.
Oh, also, this will make "foo".slice(3, 2)
horribly broken: begin <= end
still needs to be checked.
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.
:( stupid me. I'm fixing that.
The situation can still be improved by implementing a format-less |
How about doing the failure path in an |
It's a good idea. |
That's 3.3 kB IR and no formatting code inlined.
|
I'll have to rebase and rewrite the PR message. |
…ce_from Use a separate inline-never function to format failure message for str::slice() errors. Using strcat's idea, this makes sure no formatting code from failure is inlined when str::slice() is inlined. The number of `unreachable` being inlined when usingi `.slice()` drops from 5 to just 1.
It seems like |
Anyway.. it's not relevant to this change. libcore uses assert! from libcore/macros.rs |
@@ -1705,6 +1705,13 @@ pub trait StrSlice<'a> { | |||
fn utf16_units(&self) -> Utf16CodeUnits<'a>; | |||
} | |||
|
|||
#[inline(never)] |
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.
This can be #[cold]
, too
These are somewhat stop-gap solutions to address #16625 core: Separate failure formatting in str methods slice, slice_to, slice_from Use a separate inline-never function to format failure message for str::slice() errors. Using strcat's idea, this makes sure no formatting code from failure is inlined when str::slice() is inlined. The number of `unreachable` being inlined when usingi `.slice()` drops from 5 to just 1. The testcase: ``` #![crate_type = "lib"] pub fn slice(x: &str, a: uint, b: uint) -> &str { x.slice(a, b) } ``` shrinks from 16.9 kB to 3.3 kB llvm IR, and the number of `unreachable` drops from 5 to 1.
Derive `PartialEq`, `Eq` & `Hash` for `hir::Param` Since `hir::SelfParam`, as well as all members of `hir::Param` already implement `PartialEq`, `Eq` & `Hash` it seems reasonable to also make `hir::Param` implement those. (the change is motivated by an outside use of the `ra_ap_hir` crate that would benefit from being able to collect params in a `HashSet`)
These are somewhat stop-gap solutions to address #16625
core: Separate failure formatting in str methods slice, slice_to, slice_from
Use a separate inline-never function to format failure message for
str::slice() errors.
Using strcat's idea, this makes sure no formatting code from failure is
inlined when str::slice() is inlined. The number of
unreachable
beinginlined when usingi
.slice()
drops from 5 to just 1.The testcase:
shrinks from 16.9 kB to 3.3 kB llvm IR, and the number of
unreachable
drops from 5 to 1.