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;
1313use std:: sync:: Mutex ;
1414use std:: sync:: OnceLock ;
1515
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+ }
1720
1821#[ derive( Clone , Copy ) ]
1922pub struct InternedString {
@@ -60,8 +63,8 @@ impl Eq for InternedString {}
6063
6164impl InternedString {
6265 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 ( || {
6568 let s = str. to_string ( ) . leak ( ) ;
6669 cache. insert ( s) ;
6770 s
You can’t perform that action at this time.
0 commit comments