Skip to content

Commit

Permalink
Auto merge of #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 c07aa1e + 5a85565 commit cf2ef0b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions library/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 cf2ef0b

Please sign in to comment.