summaryrefslogtreecommitdiff
path: root/cli/cache
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-23 23:27:58 +0100
committerGitHub <noreply@github.com>2023-03-23 23:27:58 +0100
commit275dee60e71225a9c6c4b3b4ea7ffe4c6ecb4d87 (patch)
tree13ed3ab7e825a81085e8dcc5efeee417416b86cf /cli/cache
parentedab8f2fd48efddc19eb0032955fee4b5dbf76e6 (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')
-rw-r--r--cli/cache/check.rs20
-rw-r--r--cli/cache/emit.rs12
-rw-r--r--cli/cache/incremental.rs25
-rw-r--r--cli/cache/node.rs2
-rw-r--r--cli/cache/parsed_source.rs23
5 files changed, 41 insertions, 41 deletions
diff --git a/cli/cache/check.rs b/cli/cache/check.rs
index c8b5717ec..1bd410013 100644
--- a/cli/cache/check.rs
+++ b/cli/cache/check.rs
@@ -58,7 +58,7 @@ impl TypeCheckCache {
fn from_connection(
conn: Connection,
- cli_version: String,
+ cli_version: &'static str,
) -> Result<Self, AnyError> {
initialize(&conn, cli_version)?;
@@ -157,7 +157,10 @@ impl TypeCheckCache {
}
}
-fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
+fn initialize(
+ conn: &Connection,
+ cli_version: &'static str,
+) -> Result<(), AnyError> {
// INT doesn't store up to u64, so use TEXT for check_hash
let query = format!(
"{INITIAL_PRAGMAS}
@@ -184,12 +187,12 @@ 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 checkcache", params![])?;
conn.execute("DELETE FROM tsbuildinfo", params![])?;
let mut stmt = conn
.prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?;
- stmt.execute(params!["CLI_VERSION", &cli_version])?;
+ stmt.execute(params!["CLI_VERSION", cli_version])?;
}
Ok(())
@@ -202,8 +205,7 @@ mod test {
#[test]
pub fn check_cache_general_use() {
let conn = Connection::open_in_memory().unwrap();
- let cache =
- TypeCheckCache::from_connection(conn, "1.0.0".to_string()).unwrap();
+ let cache = TypeCheckCache::from_connection(conn, "1.0.0").unwrap();
assert!(!cache.has_check_hash(1));
cache.add_check_hash(1);
@@ -217,8 +219,7 @@ mod test {
// try changing the cli version (should clear)
let conn = cache.0.unwrap();
- let cache =
- TypeCheckCache::from_connection(conn, "2.0.0".to_string()).unwrap();
+ let cache = TypeCheckCache::from_connection(conn, "2.0.0").unwrap();
assert!(!cache.has_check_hash(1));
cache.add_check_hash(1);
assert!(cache.has_check_hash(1));
@@ -228,8 +229,7 @@ mod test {
// recreating the cache should not remove the data because the CLI version is the same
let conn = cache.0.unwrap();
- let cache =
- TypeCheckCache::from_connection(conn, "2.0.0".to_string()).unwrap();
+ let cache = TypeCheckCache::from_connection(conn, "2.0.0").unwrap();
assert!(cache.has_check_hash(1));
assert!(!cache.has_check_hash(2));
assert_eq!(cache.get_tsbuildinfo(&specifier1), Some("test".to_string()));
diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs
index 89ff496fd..dd7b9e662 100644
--- a/cli/cache/emit.rs
+++ b/cli/cache/emit.rs
@@ -22,7 +22,7 @@ struct EmitMetadata {
#[derive(Clone)]
pub struct EmitCache {
disk_cache: DiskCache,
- cli_version: String,
+ cli_version: &'static str,
}
impl EmitCache {
@@ -58,7 +58,7 @@ impl EmitCache {
// load and verify the emit is for the meta data
let emit_bytes = self.disk_cache.get(&emit_filename).ok()?;
- if meta.emit_hash != compute_emit_hash(&emit_bytes, &self.cli_version) {
+ if meta.emit_hash != compute_emit_hash(&emit_bytes, self.cli_version) {
return None;
}
@@ -113,7 +113,7 @@ impl EmitCache {
// save the metadata
let metadata = EmitMetadata {
source_hash: source_hash.to_string(),
- emit_hash: compute_emit_hash(code.as_bytes(), &self.cli_version),
+ emit_hash: compute_emit_hash(code.as_bytes(), self.cli_version),
};
self
.disk_cache
@@ -162,7 +162,7 @@ mod test {
let disk_cache = DiskCache::new(temp_dir.path());
let cache = EmitCache {
disk_cache: disk_cache.clone(),
- cli_version: "1.0.0".to_string(),
+ cli_version: "1.0.0",
};
let specifier1 =
@@ -188,7 +188,7 @@ mod test {
// try changing the cli version (should not load previous ones)
let cache = EmitCache {
disk_cache: disk_cache.clone(),
- cli_version: "2.0.0".to_string(),
+ cli_version: "2.0.0",
};
assert_eq!(cache.get_emit_code(&specifier1, 10), None);
cache.set_emit_code(&specifier1, 5, &emit_code1);
@@ -196,7 +196,7 @@ mod test {
// recreating the cache should still load the data because the CLI version is the same
let cache = EmitCache {
disk_cache,
- cli_version: "2.0.0".to_string(),
+ cli_version: "2.0.0",
};
assert_eq!(cache.get_emit_code(&specifier1, 5), Some(emit_code1));
diff --git a/cli/cache/incremental.rs b/cli/cache/incremental.rs
index 88520a031..d5298071f 100644
--- a/cli/cache/incremental.rs
+++ b/cli/cache/incremental.rs
@@ -172,7 +172,7 @@ impl SqlIncrementalCache {
fn from_connection(
conn: Connection,
state_hash: u64,
- cli_version: String,
+ cli_version: &'static str,
) -> Result<Self, AnyError> {
initialize(&conn, cli_version)?;
@@ -237,7 +237,10 @@ impl SqlIncrementalCache {
}
}
-fn initialize(conn: &Connection, cli_version: String) -> Result<(), AnyError> {
+fn initialize(
+ conn: &Connection,
+ cli_version: &'static str,
+) -> Result<(), AnyError> {
// INT doesn't store up to u64, so use TEXT for source_hash
let query = format!(
"{INITIAL_PRAGMAS}
@@ -261,11 +264,11 @@ 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 incrementalcache", params![])?;
let mut stmt = conn
.prepare("INSERT OR REPLACE INTO info (key, value) VALUES (?1, ?2)")?;
- stmt.execute(params!["CLI_VERSION", &cli_version])?;
+ stmt.execute(params!["CLI_VERSION", cli_version])?;
}
Ok(())
@@ -280,9 +283,7 @@ mod test {
#[test]
pub fn sql_cache_general_use() {
let conn = Connection::open_in_memory().unwrap();
- let cache =
- SqlIncrementalCache::from_connection(conn, 1, "1.0.0".to_string())
- .unwrap();
+ let cache = SqlIncrementalCache::from_connection(conn, 1, "1.0.0").unwrap();
let path = PathBuf::from("/mod.ts");
assert_eq!(cache.get_source_hash(&path), None);
@@ -292,8 +293,7 @@ mod test {
// try changing the cli version (should clear)
let conn = cache.conn;
let mut cache =
- SqlIncrementalCache::from_connection(conn, 1, "2.0.0".to_string())
- .unwrap();
+ SqlIncrementalCache::from_connection(conn, 1, "2.0.0").unwrap();
assert_eq!(cache.get_source_hash(&path), None);
// add back the file to the cache
@@ -310,9 +310,7 @@ mod test {
// recreating the cache should not remove the data because the CLI version and state hash is the same
let conn = cache.conn;
- let cache =
- SqlIncrementalCache::from_connection(conn, 1, "2.0.0".to_string())
- .unwrap();
+ let cache = SqlIncrementalCache::from_connection(conn, 1, "2.0.0").unwrap();
assert_eq!(cache.get_source_hash(&path), Some(2));
// now try replacing and using another path
@@ -328,8 +326,7 @@ mod test {
pub async fn incremental_cache_general_use() {
let conn = Connection::open_in_memory().unwrap();
let sql_cache =
- SqlIncrementalCache::from_connection(conn, 1, "1.0.0".to_string())
- .unwrap();
+ SqlIncrementalCache::from_connection(conn, 1, "1.0.0").unwrap();
let file_path = PathBuf::from("/mod.ts");
let file_text = "test";
let file_hash = FastInsecureHasher::new().write_str(file_text).finish();
diff --git a/cli/cache/node.rs b/cli/cache/node.rs
index e010c0dcd..19ac45d6b 100644
--- a/cli/cache/node.rs
+++ b/cli/cache/node.rs
@@ -102,7 +102,7 @@ impl NodeAnalysisCache {
None => {
let maybe_inner = match NodeAnalysisCacheInner::new(
self.db_file_path.as_deref(),
- crate::version::deno(),
+ crate::version::deno().to_string(),
) {
Ok(cache) => Some(cache),
Err(err) => {
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();