File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 11use serde:: { Serialize , Serializer } ;
22use serde_untagged:: UntaggedEnumVisitor ;
33use std:: borrow:: Borrow ;
4+ use std:: borrow:: Cow ;
45use std:: cmp:: Ordering ;
56use std:: collections:: HashSet ;
67use std:: ffi:: OsStr ;
@@ -46,7 +47,7 @@ impl<'a> From<&'a String> for InternedString {
4647
4748impl From < String > for InternedString {
4849 fn from ( item : String ) -> Self {
49- InternedString :: new ( & item)
50+ InternedString :: from_cow ( item. into ( ) )
5051 }
5152}
5253
@@ -72,9 +73,13 @@ impl Eq for InternedString {}
7273
7374impl InternedString {
7475 pub fn new ( str : & str ) -> InternedString {
76+ InternedString :: from_cow ( str. into ( ) )
77+ }
78+
79+ fn from_cow < ' a > ( str : Cow < ' a , str > ) -> InternedString {
7580 let mut cache = interned_storage ( ) ;
76- let s = cache. get ( str) . copied ( ) . unwrap_or_else ( || {
77- let s = str. to_string ( ) . leak ( ) ;
81+ let s = cache. get ( str. as_ref ( ) ) . copied ( ) . unwrap_or_else ( || {
82+ let s = str. into_owned ( ) . leak ( ) ;
7883 cache. insert ( s) ;
7984 s
8085 } ) ;
You can’t perform that action at this time.
0 commit comments