This first compares the `Repr` before falling back to actually comparing the raw `as_str` itself.
In some micro-benchmarks, this speeds up inline and heap string comparisons when equal by ~70%.
There is a tiny hit in the non-equal case however. It is also noteworthy that the assembly generated for `Repr` is horrible,
and looks like its above the inlining threshold now.
This regressed from a previous attempt.
The worst of the old results were in the range 450.000
current:
test bench::bench_derive_clone ... bench: 1,653,247 ns/iter (+/- 32,781)
test bench::bench_match_clone ... bench: 1,716,482 ns/iter (+/- 34,192)
test bench::bench_new_clone ... bench: 1,717,985 ns/iter (+/- 52,137)
Allows creating `SmolStr`s longer than 23 bytes in constant
contexts.
This is done by replacing the `Repr::Substring` variant by a more
general `Repr::Static(&'static str)` variant, and borrowing from ̀`WS`
directly instead of storing two `usize`s.
As a bonus, it also simplifies the `as_str` implementation, hopefully
saving an extra branch.
21: Add a new test for a bad size hint r=bjorn3 a=Dr-Emann
Changes in PR rust-analyzer/smol_str#20 allow for an incorrect size hint to create a non-canonical SmolStr. Add a new test which will fail if we ever rely on
SmolStrs to be canonical when comparing for equality.
Co-authored-by: Zachary Dremann <dremann@gmail.com>
Changes in PR rust-analyzer/smol_str#20 allow for an incorrect size hint to create a
non-canonical SmolStr. Add a new test which will fail if we ever rely on
SmolStrs to be canonical when comparing for equality.
41: Remove unnecessary `Into<String>` bound from `From<T>` impl r=Veykril a=Veykril
Looks like this was forgotten when the bound got removed from the `new` constructor
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>