diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-04-14 16:22:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 16:22:33 -0400 |
commit | 136dce67cec749dce5989ea29e88359ef79a0045 (patch) | |
tree | 38e96bbbf22dc06cdba418a35467b215f1335549 /cli/emit.rs | |
parent | a4111442191fff300132259752e6d2d5613d1871 (diff) |
refactor: break up `ProcState` (#18707)
1. Breaks up functionality within `ProcState` into several other structs
to break out the responsibilities (`ProcState` is only a data struct
now).
2. Moves towards being able to inject dependencies more easily and have
functionality only require what it needs.
3. Exposes `Arc<T>` around the "service structs" instead of it being
embedded within them. The idea behind embedding them was to reduce the
verbosity of needing to pass around `Arc<...>`, but I don't think it was
exactly working and as we move more of these structs to be more
injectable I don't think the extra verbosity will be a big deal.
Diffstat (limited to 'cli/emit.rs')
-rw-r--r-- | cli/emit.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/cli/emit.rs b/cli/emit.rs index 92c240950..6d3419579 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -12,10 +12,9 @@ use deno_graph::Module; use deno_graph::ModuleGraph; use std::sync::Arc; -#[derive(Clone)] pub struct Emitter { emit_cache: EmitCache, - parsed_source_cache: ParsedSourceCache, + parsed_source_cache: Arc<ParsedSourceCache>, emit_options: deno_ast::EmitOptions, // cached hash of the emit options emit_options_hash: u64, @@ -24,7 +23,7 @@ pub struct Emitter { impl Emitter { pub fn new( emit_cache: EmitCache, - parsed_source_cache: ParsedSourceCache, + parsed_source_cache: Arc<ParsedSourceCache>, emit_options: deno_ast::EmitOptions, ) -> Self { let emit_options_hash = FastInsecureHasher::new() @@ -64,6 +63,16 @@ impl Emitter { Ok(()) } + /// Gets a cached emit if the source matches the hash found in the cache. + pub fn maybed_cached_emit( + &self, + specifier: &ModuleSpecifier, + source: &str, + ) -> Option<String> { + let source_hash = self.get_source_hash(source); + self.emit_cache.get_emit_code(specifier, source_hash) + } + pub fn emit_parsed_source( &self, specifier: &ModuleSpecifier, @@ -97,7 +106,7 @@ impl Emitter { /// A hashing function that takes the source code and uses the global emit /// options then generates a string hash which can be stored to /// determine if the cached emit is valid or not. - pub fn get_source_hash(&self, source_text: &str) -> u64 { + fn get_source_hash(&self, source_text: &str) -> u64 { FastInsecureHasher::new() .write_str(source_text) .write_u64(self.emit_options_hash) |