Skip to content

Commit

Permalink
Auto merge of rust-lang#132705 - kornelski:inline-repeat, r=tgross35
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Nov 7, 2024
2 parents 7a82eb5 + 95bff3e commit 8022523
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ impl str {
#[rustc_allow_incoherent_impl]
#[must_use]
#[stable(feature = "repeat_str", since = "1.16.0")]
#[inline]
pub fn repeat(&self, n: usize) -> String {
unsafe { String::from_utf8_unchecked(self.as_bytes().repeat(n)) }
}
Expand Down

0 comments on commit 8022523

Please sign in to comment.