-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use char instead of &str for single char patterns #69481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after removing unnecessary escapes.
b974a81
to
8ceb909
Compare
@bors r+ rollup=always |
📌 Commit 8ceb9096ac72bab8b5566f22645c16e84634603f has been approved by |
failed in rollup |
Rollup of 4 pull requests Successful merges: - #69439 (resolve: `lifetimes.rs` -> `late/lifetimes.rs`) - #69473 (update llvm to silence gcc 9 warnings) - #69479 (clarify operator precedence) - #69480 (Clean up E0373 explanation) Failed merges: - #69481 (use char instead of &str for single char patterns) - #69496 (use find(x) instead of filter(x).next()) r? @ghost
#41993 was fixed, but I still think this replacement is ideologically wrong. |
When running these benchmarks that I found via the discussion you linked #![feature(test)]
extern crate test;
use crate::test::black_box;
use crate::test::Bencher;
fn main() {
println!("Hello, world!");
}
#[bench]
fn starts_with_char(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.starts_with('k'));
}
})
}
#[bench]
fn starts_with_str(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.starts_with("k"));
}
})
}
#[bench]
fn ends_with_char(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.ends_with('k'));
}
})
}
#[bench]
fn ends_with_str(b: &mut Bencher) {
let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
b.iter(|| {
for _ in 0..1024 {
black_box(text.ends_with("k"));
}
})
} , char is consistently faster for me with default optimization levels:
|
If this is a perf improvement now, rather than just a stylistic change, then it should be ok. |
☔ The latest upstream changes (presumably #69507) made this pull request unmergeable. Please resolve the merge conflicts. |
8ceb909
to
7c84ba1
Compare
rebased |
r? @petrochenkov or @ecstatic-morse |
@bors r=ecstatic-morse |
📌 Commit 7c84ba1 has been approved by |
Rollup of 10 pull requests Successful merges: - #68989 (Update RELEASES.md for 1.42.0) - #69340 (instantiate_value_path: on `SelfCtor`, avoid unconstrained tyvars) - #69384 (parser: `token` -> `normalized_token`, `nonnormalized_token` -> `token`) - #69452 (typeck: use `Pattern` obligation cause more for better diagnostics) - #69481 (use char instead of &str for single char patterns) - #69522 (error_derive_forbidden_on_non_adt: be more graceful) - #69538 (Stabilize `boxed_slice_try_from`) - #69539 (late resolve, visit_fn: bail early if there's no body.) - #69541 (Remove unneeded calls to format!()) - #69547 (remove redundant clones, references to operands, explicit boolean comparisons and filter(x).next() calls.) Failed merges: r? @ghost
No description provided.