mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
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.
This commit is contained in:
parent
a411144219
commit
136dce67ce
33 changed files with 1506 additions and 1285 deletions
17
cli/emit.rs
17
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue