File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ use std::str;
13
13
use std:: sync:: Mutex ;
14
14
use std:: sync:: OnceLock ;
15
15
16
- static STRING_CACHE : OnceLock < Mutex < HashSet < & ' static str > > > = OnceLock :: new ( ) ;
16
+ fn interned_storage ( ) -> std:: sync:: MutexGuard < ' static , HashSet < & ' static str > > {
17
+ static STRING_CACHE : OnceLock < Mutex < HashSet < & ' static str > > > = OnceLock :: new ( ) ;
18
+ STRING_CACHE . get_or_init ( Default :: default) . lock ( ) . unwrap ( )
19
+ }
17
20
18
21
#[ derive( Clone , Copy ) ]
19
22
pub struct InternedString {
@@ -60,8 +63,8 @@ impl Eq for InternedString {}
60
63
61
64
impl InternedString {
62
65
pub fn new ( str : & str ) -> InternedString {
63
- let mut cache = STRING_CACHE . get_or_init ( Default :: default ) . lock ( ) . unwrap ( ) ;
64
- let s = cache. get ( str) . cloned ( ) . unwrap_or_else ( || {
66
+ let mut cache = interned_storage ( ) ;
67
+ let s = cache. get ( str) . copied ( ) . unwrap_or_else ( || {
65
68
let s = str. to_string ( ) . leak ( ) ;
66
69
cache. insert ( s) ;
67
70
s
You can’t perform that action at this time.
0 commit comments