diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-23 23:27:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-23 23:27:58 +0100 |
commit | 275dee60e71225a9c6c4b3b4ea7ffe4c6ecb4d87 (patch) | |
tree | 13ed3ab7e825a81085e8dcc5efeee417416b86cf /cli/cache/parsed_source.rs | |
parent | edab8f2fd48efddc19eb0032955fee4b5dbf76e6 (diff) |
refactor: make version and user_agent &'static str (#18400)
These caused a bunch of unnecessary allocations on each startup.
Diffstat (limited to 'cli/cache/parsed_source.rs')
-rw-r--r-- | cli/cache/parsed_source.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/cli/cache/parsed_source.rs b/cli/cache/parsed_source.rs index 7b183ce86..2f27f0533 100644 --- a/cli/cache/parsed_source.rs +++ b/cli/cache/parsed_source.rs @@ -54,7 +54,7 @@ impl deno_graph::ParsedSourceStore for ParsedSourceCacheSources { #[derive(Clone)] pub struct ParsedSourceCache { db_cache_path: Option<PathBuf>, - cli_version: String, + cli_version: &'static str, sources: ParsedSourceCacheSources, } @@ -70,7 +70,7 @@ impl ParsedSourceCache { pub fn reset_for_file_watcher(&self) -> Self { Self { db_cache_path: self.db_cache_path.clone(), - cli_version: self.cli_version.clone(), + cli_version: self.cli_version, sources: Default::default(), } } @@ -116,7 +116,7 @@ impl ParsedSourceCache { pub fn as_analyzer(&self) -> Box<dyn deno_graph::ModuleAnalyzer> { match ParsedSourceCacheModuleAnalyzer::new( self.db_cache_path.as_deref(), - self.cli_version.clone(), + self.cli_version, self.sources.clone(), ) { Ok(analyzer) => Box::new(analyzer), @@ -146,7 +146,7 @@ struct ParsedSourceCacheModuleAnalyzer { impl ParsedSourceCacheModuleAnalyzer { pub fn new( db_file_path: Option<&Path>, - cli_version: String, + cli_version: &'static str, sources: ParsedSourceCacheSources, ) -> Result<Self, AnyError> { log::debug!("Loading cached module analyzer."); @@ -159,7 +159,7 @@ impl ParsedSourceCacheModuleAnalyzer { fn from_connection( conn: Connection, - cli_version: String, + cli_version: &'static str, sources: ParsedSourceCacheSources, ) -> Result<Self, AnyError> { initialize(&conn, cli_version)?; @@ -287,7 +287,10 @@ impl deno_graph::ModuleAnalyzer for ParsedSourceCacheModuleAnalyzer { } } -fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> { +fn initialize( + conn: &Connection, + cli_version: &'static str, +) -> Result<(), AnyError> { let query = format!( "{INITIAL_PRAGMAS} -- INT doesn't store up to u64, so use TEXT for source_hash @@ -314,7 +317,7 @@ fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> { |row| row.get(0), ) .ok(); - if data_cli_version.as_deref() != Some(&cli_version) { + if data_cli_version.as_deref() != Some(cli_version) { conn.execute("DELETE FROM moduleinfocache", params![])?; let mut stmt = conn .prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?; @@ -340,7 +343,7 @@ mod test { let conn = Connection::open_in_memory().unwrap(); let cache = ParsedSourceCacheModuleAnalyzer::from_connection( conn, - "1.0.0".to_string(), + "1.0.0", Default::default(), ) .unwrap(); @@ -403,7 +406,7 @@ mod test { let conn = cache.conn; let cache = ParsedSourceCacheModuleAnalyzer::from_connection( conn, - "1.0.0".to_string(), + "1.0.0", Default::default(), ) .unwrap(); @@ -420,7 +423,7 @@ mod test { let conn = cache.conn; let cache = ParsedSourceCacheModuleAnalyzer::from_connection( conn, - "1.0.1".to_string(), + "1.0.1", Default::default(), ) .unwrap(); |