diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-05-01 14:35:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 14:35:23 -0400 |
commit | 9efed4c7a3d32de62e9c9b5e0c6712ce97637abb (patch) | |
tree | aa370f95df93c71f6c57d6a01a50b4df1955ee57 /cli/cache/caches.rs | |
parent | 30628288ce2b411ca3def46129a4606073e16bac (diff) |
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.
Diffstat (limited to 'cli/cache/caches.rs')
-rw-r--r-- | cli/cache/caches.rs | 33 |
1 files changed, 22 insertions, 11 deletions
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<CacheDB>, lint_incremental_cache_db: OnceCell<CacheDB>, dep_analysis_db: OnceCell<CacheDB>, @@ -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<CacheDB>, 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(), ) } } |