Slight simplification of chars().count()#81409
Conversation
|
(rust-highfive has picked a reviewer for you, use r? to override) |
|
Is there a github command to kick off a performance comparison? I'm not sure we'd see much of an improvement but it seems a simpler way to define the function. |
|
How about
|
|
It doesn't look like this makes any difference https://godbolt.org/z/vKhTo9
There's one to profile the compiler, but I don't this is the case. Usually you just locally run the relevant benchmarks and post the results. ps: Does anyone know why the related benches are in |
I think you're looking at the diff backwards,
Even better IMO. |
|
Nice simplification! |
|
Godbolt has nice diffs! It shows that filter count has exactly the same instructions as map sum so I'll change it to filter count (as the intent is clearer). |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
d0eb2d6 to
a623ea5
Compare
|
(@SkiFire13 thanks for pointing out where the benchmarks were.) Before: After: So seems no noticable difference in performance which given it only shaves a few instructions off I guess is to be expected. |
|
Looks reasonable to me. Nice improvement. @bors r+ |
|
📌 Commit a623ea5 has been approved by |
Slight simplification of chars().count() Slight simplification: No need to call len(), we can just count the number of non continuation bytes. I can't see any reason not to do this, can you?
fn count(self) -> usize {
self.iter.filter(|&&byte| !utf8_is_cont_byte(byte)).take(usize::MAX).count()
}This somehow generates smaller code, but maybe it slower? |
|
That doesn't vectorize the loop so yes, it would probably be slower |
Rollup of 16 pull requests Successful merges: - rust-lang#79023 (Add `core::stream::Stream`) - rust-lang#80562 (Consider Scalar to be a bool only if its unsigned) - rust-lang#80886 (Stabilize raw ref macros) - rust-lang#80959 (Stabilize `unsigned_abs`) - rust-lang#81291 (Support FRU pattern with `[feature(capture_disjoint_fields)]`) - rust-lang#81409 (Slight simplification of chars().count()) - rust-lang#81468 (cfg(version): treat nightlies as complete) - rust-lang#81473 (Warn write-only fields) - rust-lang#81495 (rustdoc: Remove unnecessary optional) - rust-lang#81499 (Updated Vec::splice documentation) - rust-lang#81501 (update rustfmt to v1.4.34) - rust-lang#81505 (`fn cold_path` doesn't need to be pub) - rust-lang#81512 (Add missing variants in match binding) - rust-lang#81515 (Fix typo in pat.rs) - rust-lang#81519 (Don't print error output from rustup when detecting default build triple) - rust-lang#81520 (Don't clone LLVM submodule when download-ci-llvm is set) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Slight simplification: No need to call len(), we can just count the number of non continuation bytes.
I can't see any reason not to do this, can you?