From 9efed4c7a3d32de62e9c9b5e0c6712ce97637abb Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 1 May 2023 14:35:23 -0400 Subject: refactor(cli): remove ProcState - add CliFactory (#18900) This removes `ProcState` and replaces it with a new `CliFactory` which initializes our "service structs" on demand. This isn't a performance improvement at the moment for `deno run`, but might unlock performance improvements in the future. --- cli/cache/caches.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'cli/cache') diff --git a/cli/cache/caches.rs b/cli/cache/caches.rs index 0b60d0bec..62bec8a00 100644 --- a/cli/cache/caches.rs +++ b/cli/cache/caches.rs @@ -12,8 +12,8 @@ use super::node::NODE_ANALYSIS_CACHE_DB; use super::parsed_source::PARSED_SOURCE_CACHE_DB; use super::DenoDir; -#[derive(Default)] pub struct Caches { + dir: DenoDir, fmt_incremental_cache_db: OnceCell, lint_incremental_cache_db: OnceCell, dep_analysis_db: OnceCell, @@ -22,6 +22,17 @@ pub struct Caches { } impl Caches { + pub fn new(dir: DenoDir) -> Self { + Self { + dir, + fmt_incremental_cache_db: Default::default(), + lint_incremental_cache_db: Default::default(), + dep_analysis_db: Default::default(), + node_analysis_db: Default::default(), + type_checking_cache_db: Default::default(), + } + } + fn make_db( cell: &OnceCell, config: &'static CacheDBConfiguration, @@ -32,43 +43,43 @@ impl Caches { .clone() } - pub fn fmt_incremental_cache_db(&self, dir: &DenoDir) -> CacheDB { + pub fn fmt_incremental_cache_db(&self) -> CacheDB { Self::make_db( &self.fmt_incremental_cache_db, &INCREMENTAL_CACHE_DB, - dir.fmt_incremental_cache_db_file_path(), + self.dir.fmt_incremental_cache_db_file_path(), ) } - pub fn lint_incremental_cache_db(&self, dir: &DenoDir) -> CacheDB { + pub fn lint_incremental_cache_db(&self) -> CacheDB { Self::make_db( &self.lint_incremental_cache_db, &INCREMENTAL_CACHE_DB, - dir.lint_incremental_cache_db_file_path(), + self.dir.lint_incremental_cache_db_file_path(), ) } - pub fn dep_analysis_db(&self, dir: &DenoDir) -> CacheDB { + pub fn dep_analysis_db(&self) -> CacheDB { Self::make_db( &self.dep_analysis_db, &PARSED_SOURCE_CACHE_DB, - dir.dep_analysis_db_file_path(), + self.dir.dep_analysis_db_file_path(), ) } - pub fn node_analysis_db(&self, dir: &DenoDir) -> CacheDB { + pub fn node_analysis_db(&self) -> CacheDB { Self::make_db( &self.node_analysis_db, &NODE_ANALYSIS_CACHE_DB, - dir.node_analysis_db_file_path(), + self.dir.node_analysis_db_file_path(), ) } - pub fn type_checking_cache_db(&self, dir: &DenoDir) -> CacheDB { + pub fn type_checking_cache_db(&self) -> CacheDB { Self::make_db( &self.type_checking_cache_db, &TYPE_CHECK_CACHE_DB, - dir.type_checking_cache_db_file_path(), + self.dir.type_checking_cache_db_file_path(), ) } } -- cgit v1.2.3