Auto merge of #132705 - kornelski:inline-repeat, r=tgross35
Inline str::repeat `str` is non-generic and `str.repeat()` doesn't get inlined, which makes it use a slower algorithm in case of 1-char repetitions. Equivalent byte slice does get inlined: https://rust.godbolt.org/z/4arvh97r4
This commit is contained in:
commit
546a1eaab9
@ -531,6 +531,7 @@ pub fn into_string(self: Box<str>) -> String {
|
|||||||
#[rustc_allow_incoherent_impl]
|
#[rustc_allow_incoherent_impl]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "repeat_str", since = "1.16.0")]
|
#[stable(feature = "repeat_str", since = "1.16.0")]
|
||||||
|
#[inline]
|
||||||
pub fn repeat(&self, n: usize) -> String {
|
pub fn repeat(&self, n: usize) -> String {
|
||||||
unsafe { String::from_utf8_unchecked(self.as_bytes().repeat(n)) }
|
unsafe { String::from_utf8_unchecked(self.as_bytes().repeat(n)) }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user