Skip to content

Commit 44e8d91

Browse files
authored
Rollup merge of rust-lang#125609 - diondokter:opt-size-char-count, r=thomcc
Always use the general case char count with `optimize_for_size` The faster algo is really expensive, over a kilobyte if the full algo is present in a binary. With this PR the general case algo is picked always instead of only for small strings. In a test of mine this change makes the total binary go from 3116 bytes to 2032 bytes in opt-level 3 and from 1652 bytes to 1428 bytes in opt-level z. I've seen it much worse in real application, so the savings (especially on 'z') will be higher in many cases. This is the second pr of this kind after rust-lang#125606
2 parents 1f1f9e1 + 05fa647 commit 44e8d91

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/core/src/str/count.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const UNROLL_INNER: usize = 4;
2424

2525
#[inline]
2626
pub(super) fn count_chars(s: &str) -> usize {
27-
if s.len() < USIZE_SIZE * UNROLL_INNER {
27+
if cfg!(feature = "optimize_for_size") || s.len() < USIZE_SIZE * UNROLL_INNER {
2828
// Avoid entering the optimized implementation for strings where the
2929
// difference is not likely to matter, or where it might even be slower.
3030
// That said, a ton of thought was not spent on the particular threshold

0 commit comments

Comments
 (0)