@@ -13,6 +13,7 @@ use crate::args::CliOptions;
13
13
use crate :: args:: DenoSubcommand ;
14
14
use crate :: args:: TsTypeLib ;
15
15
use crate :: cache:: CodeCache ;
16
+ use crate :: cache:: FastInsecureHasher ;
16
17
use crate :: cache:: ModuleInfoCache ;
17
18
use crate :: cache:: ParsedSourceCache ;
18
19
use crate :: emit:: Emitter ;
@@ -51,6 +52,7 @@ use deno_core::ModuleCodeString;
51
52
use deno_core:: ModuleLoader ;
52
53
use deno_core:: ModuleSource ;
53
54
use deno_core:: ModuleSourceCode ;
55
+ use deno_core:: ModuleSourceCodeCache ;
54
56
use deno_core:: ModuleSpecifier ;
55
57
use deno_core:: ModuleType ;
56
58
use deno_core:: RequestedModuleType ;
@@ -388,27 +390,24 @@ impl<TGraphContainer: ModuleGraphContainer>
388
390
}
389
391
390
392
let code_cache = if module_type == ModuleType :: JavaScript {
391
- self . shared . code_cache . as_ref ( ) . and_then ( |cache| {
392
- let code_hash = self
393
- . get_code_hash_or_timestamp ( specifier, code_source. media_type )
394
- . ok ( )
395
- . flatten ( ) ;
396
- if let Some ( code_hash) = code_hash {
397
- cache
398
- . get_sync (
399
- specifier. as_str ( ) ,
400
- code_cache:: CodeCacheType :: EsModule ,
401
- & code_hash,
402
- )
403
- . map ( Cow :: from)
404
- . inspect ( |_| {
405
- // This log line is also used by tests.
406
- log:: debug!(
407
- "V8 code cache hit for ES module: {specifier}, [{code_hash:?}]"
408
- ) ;
409
- } )
410
- } else {
411
- None
393
+ self . shared . code_cache . as_ref ( ) . map ( |cache| {
394
+ let code_hash = FastInsecureHasher :: hash ( & code) ;
395
+ let data = cache
396
+ . get_sync (
397
+ specifier. as_str ( ) ,
398
+ code_cache:: CodeCacheType :: EsModule ,
399
+ & code_hash. to_string ( ) ,
400
+ )
401
+ . map ( Cow :: from)
402
+ . inspect ( |_| {
403
+ // This log line is also used by tests.
404
+ log:: debug!(
405
+ "V8 code cache hit for ES module: {specifier}, [{code_hash:?}]"
406
+ ) ;
407
+ } ) ;
408
+ ModuleSourceCodeCache {
409
+ hash : code_hash,
410
+ data,
412
411
}
413
412
} )
414
413
} else {
@@ -589,25 +588,6 @@ impl<TGraphContainer: ModuleGraphContainer>
589
588
resolution. map_err ( |err| err. into ( ) )
590
589
}
591
590
592
- fn get_code_hash_or_timestamp (
593
- & self ,
594
- specifier : & ModuleSpecifier ,
595
- media_type : MediaType ,
596
- ) -> Result < Option < String > , AnyError > {
597
- let hash = self
598
- . shared
599
- . module_info_cache
600
- . get_module_source_hash ( specifier, media_type) ?;
601
- if let Some ( hash) = hash {
602
- return Ok ( Some ( hash. into ( ) ) ) ;
603
- }
604
-
605
- // Use the modified timestamp from the local file system if we don't have a hash.
606
- let timestamp = code_timestamp ( specifier. as_str ( ) )
607
- . map ( |timestamp| timestamp. to_string ( ) ) ?;
608
- Ok ( Some ( timestamp) )
609
- }
610
-
611
591
async fn load_prepared_module (
612
592
& self ,
613
593
specifier : & ModuleSpecifier ,
@@ -866,27 +846,20 @@ impl<TGraphContainer: ModuleGraphContainer> ModuleLoader
866
846
fn code_cache_ready (
867
847
& self ,
868
848
specifier : & ModuleSpecifier ,
849
+ hash : u64 ,
869
850
code_cache : & [ u8 ] ,
870
851
) -> Pin < Box < dyn Future < Output = ( ) > > > {
871
852
if let Some ( cache) = self . 0 . shared . code_cache . as_ref ( ) {
872
- let media_type = MediaType :: from_specifier ( specifier) ;
873
- let code_hash = self
874
- . 0
875
- . get_code_hash_or_timestamp ( specifier, media_type)
876
- . ok ( )
877
- . flatten ( ) ;
878
- if let Some ( code_hash) = code_hash {
879
- // This log line is also used by tests.
880
- log:: debug!(
881
- "Updating V8 code cache for ES module: {specifier}, [{code_hash:?}]"
882
- ) ;
883
- cache. set_sync (
884
- specifier. as_str ( ) ,
885
- code_cache:: CodeCacheType :: EsModule ,
886
- & code_hash,
887
- code_cache,
888
- ) ;
889
- }
853
+ // This log line is also used by tests.
854
+ log:: debug!(
855
+ "Updating V8 code cache for ES module: {specifier}, [{hash}]"
856
+ ) ;
857
+ cache. set_sync (
858
+ specifier. as_str ( ) ,
859
+ code_cache:: CodeCacheType :: EsModule ,
860
+ & hash. to_string ( ) ,
861
+ code_cache,
862
+ ) ;
890
863
}
891
864
std:: future:: ready ( ( ) ) . boxed_local ( )
892
865
}
0 commit comments