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 1
1
use serde:: { Serialize , Serializer } ;
2
2
use serde_untagged:: UntaggedEnumVisitor ;
3
3
use std:: borrow:: Borrow ;
4
+ use std:: borrow:: Cow ;
4
5
use std:: cmp:: Ordering ;
5
6
use std:: collections:: HashSet ;
6
7
use std:: ffi:: OsStr ;
@@ -46,7 +47,7 @@ impl<'a> From<&'a String> for InternedString {
46
47
47
48
impl From < String > for InternedString {
48
49
fn from ( item : String ) -> Self {
49
- InternedString :: new ( & item)
50
+ InternedString :: from_cow ( item. into ( ) )
50
51
}
51
52
}
52
53
@@ -72,9 +73,13 @@ impl Eq for InternedString {}
72
73
73
74
impl InternedString {
74
75
pub fn new ( str : & str ) -> InternedString {
76
+ InternedString :: from_cow ( str. into ( ) )
77
+ }
78
+
79
+ fn from_cow < ' a > ( str : Cow < ' a , str > ) -> InternedString {
75
80
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 ( ) ;
78
83
cache. insert ( s) ;
79
84
s
80
85
} ) ;
You can’t perform that action at this time.
0 commit comments