1- use std:: collections:: HashMap ;
21use std:: io;
32use std:: sync:: Arc ;
4- use std:: sync:: Mutex ;
53
64use camino:: Utf8Path ;
75use camino:: Utf8PathBuf ;
86use djls_source:: Db as SourceDb ;
97use djls_source:: File ;
8+ use djls_source:: FxDashMap ;
109use djls_templates:: Db as TemplateDb ;
1110use salsa:: Setter ;
1211
1312#[ salsa:: db]
1413#[ derive( Clone ) ]
1514pub struct Db {
16- sources : Arc < Mutex < HashMap < Utf8PathBuf , String > > > ,
15+ sources : Arc < FxDashMap < Utf8PathBuf , String > > ,
1716 storage : salsa:: Storage < Self > ,
1817}
1918
2019impl Db {
2120 #[ must_use]
2221 pub fn new ( ) -> Self {
2322 Self {
24- sources : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
23+ sources : Arc :: new ( FxDashMap :: default ( ) ) ,
2524 storage : salsa:: Storage :: default ( ) ,
2625 }
2726 }
2827
29- /// ## Panics
30- ///
31- /// If sources mutex is poisoned.
3228 pub fn file_with_contents ( & mut self , path : Utf8PathBuf , contents : & str ) -> File {
33- self . sources
34- . lock ( )
35- . expect ( "sources lock poisoned" )
36- . insert ( path. clone ( ) , contents. to_string ( ) ) ;
29+ self . sources . insert ( path. clone ( ) , contents. to_string ( ) ) ;
3730 File :: new ( self , path, 0 )
3831 }
3932
40- /// ## Panics
41- ///
42- /// If sources mutex is poisoned.
4333 pub fn set_file_contents ( & mut self , file : File , contents : & str , revision : u64 ) {
4434 let path = file. path ( self ) ;
45- self . sources
46- . lock ( )
47- . expect ( "sources lock poisoned" )
48- . insert ( path. clone ( ) , contents. to_string ( ) ) ;
35+ self . sources . insert ( path. clone ( ) , contents. to_string ( ) ) ;
4936 file. set_revision ( self ) . to ( revision) ;
5037 }
5138}
@@ -62,8 +49,11 @@ impl salsa::Database for Db {}
6249#[ salsa:: db]
6350impl SourceDb for Db {
6451 fn read_file_source ( & self , path : & Utf8Path ) -> io:: Result < String > {
65- let sources = self . sources . lock ( ) . expect ( "sources lock poisoned" ) ;
66- Ok ( sources. get ( path) . cloned ( ) . unwrap_or_default ( ) )
52+ Ok ( self
53+ . sources
54+ . get ( path)
55+ . map ( |entry| entry. value ( ) . clone ( ) )
56+ . unwrap_or_default ( ) )
6757 }
6858}
6959
0 commit comments