This repository was archived by the owner on Nov 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55- Optimise ` StrExt::replace_smolstr ` , ` StrExt::replacen_smolstr ` for single ascii replace,
66 ~ 3x speedup inline & heap.
7+ - Optimise ` StrExt::to_ascii_lowercase_smolstr ` , ` StrExt::to_ascii_uppercase_smolstr `
8+ ~ 2x speedup inline, ~ 4-22x for heap.
79
810## 0.3.2 - 2024-10-23
911
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1212all-features = true
1313
1414[dependencies ]
15- serde = { version = " 1.0" , optional = true , default-features = false }
15+ serde_core = { version = " 1.0.220 " , optional = true , default-features = false }
1616borsh = { version = " 1.4.0" , optional = true , default-features = false }
1717arbitrary = { version = " 1.3" , optional = true }
1818
@@ -23,4 +23,5 @@ serde = { version = "1.0", features = ["derive"] }
2323
2424[features ]
2525default = [" std" ]
26- std = [" serde?/std" , " borsh?/std" ]
26+ std = [" serde_core?/std" , " borsh?/std" ]
27+ serde = [" dep:serde_core" ]
Original file line number Diff line number Diff line change @@ -644,12 +644,36 @@ impl StrExt for str {
644644
645645 #[ inline]
646646 fn to_ascii_lowercase_smolstr ( & self ) -> SmolStr {
647- from_char_iter ( self . chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) )
647+ let len = self . len ( ) ;
648+ if len <= INLINE_CAP {
649+ let mut buf = [ 0u8 ; INLINE_CAP ] ;
650+ buf[ ..len] . copy_from_slice ( self . as_bytes ( ) ) ;
651+ buf[ ..len] . make_ascii_lowercase ( ) ;
652+ SmolStr ( Repr :: Inline {
653+ // SAFETY: `len` is in bounds
654+ len : unsafe { InlineSize :: transmute_from_u8 ( len as u8 ) } ,
655+ buf,
656+ } )
657+ } else {
658+ self . to_ascii_lowercase ( ) . into ( )
659+ }
648660 }
649661
650662 #[ inline]
651663 fn to_ascii_uppercase_smolstr ( & self ) -> SmolStr {
652- from_char_iter ( self . chars ( ) . map ( |c| c. to_ascii_uppercase ( ) ) )
664+ let len = self . len ( ) ;
665+ if len <= INLINE_CAP {
666+ let mut buf = [ 0u8 ; INLINE_CAP ] ;
667+ buf[ ..len] . copy_from_slice ( self . as_bytes ( ) ) ;
668+ buf[ ..len] . make_ascii_uppercase ( ) ;
669+ SmolStr ( Repr :: Inline {
670+ // SAFETY: `len` is in bounds
671+ len : unsafe { InlineSize :: transmute_from_u8 ( len as u8 ) } ,
672+ buf,
673+ } )
674+ } else {
675+ self . to_ascii_uppercase ( ) . into ( )
676+ }
653677 }
654678
655679 #[ inline]
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use alloc::{string::String, vec::Vec};
22use core:: fmt;
33
44use serde:: de:: { Deserializer , Error , Unexpected , Visitor } ;
5+ use serde_core as serde;
56
67use crate :: SmolStr ;
78
You can’t perform that action at this time.
0 commit comments