summaryrefslogtreecommitdiff
path: root/cli/cache
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-07-10 17:45:09 -0400
committerGitHub <noreply@github.com>2023-07-10 21:45:09 +0000
commit8dd9d5f5239f9f842f7096a540f866bd4f10b72c (patch)
tree159ea977036a2ed76ce61d3ba2da9239a6f287a3 /cli/cache
parent629d09b149ab42cc4c3cebc41e0f23112ace891c (diff)
refactor(lsp): move config file related code to config.rs (#19790)
Will make #19788 easier.
Diffstat (limited to 'cli/cache')
-rw-r--r--cli/cache/common.rs6
-rw-r--r--cli/cache/incremental.rs13
-rw-r--r--cli/cache/node.rs5
-rw-r--r--cli/cache/parsed_source.rs2
4 files changed, 12 insertions, 14 deletions
diff --git a/cli/cache/common.rs b/cli/cache/common.rs
index 93ff91d50..3e2e862aa 100644
--- a/cli/cache/common.rs
+++ b/cli/cache/common.rs
@@ -11,6 +11,10 @@ impl FastInsecureHasher {
Self::default()
}
+ pub fn hash(hashable: impl std::hash::Hash) -> u64 {
+ Self::new().write_hashable(hashable).finish()
+ }
+
pub fn write_str(&mut self, text: &str) -> &mut Self {
self.write(text.as_bytes());
self
@@ -33,7 +37,7 @@ impl FastInsecureHasher {
pub fn write_hashable(
&mut self,
- hashable: &impl std::hash::Hash,
+ hashable: impl std::hash::Hash,
) -> &mut Self {
hashable.hash(&mut self.0);
self
diff --git a/cli/cache/incremental.rs b/cli/cache/incremental.rs
index c50b876fa..04ac4243b 100644
--- a/cli/cache/incremental.rs
+++ b/cli/cache/incremental.rs
@@ -72,9 +72,8 @@ impl IncrementalCacheInner {
state: &TState,
initial_file_paths: &[PathBuf],
) -> Self {
- let state_hash = FastInsecureHasher::new()
- .write_str(&serde_json::to_string(state).unwrap())
- .finish();
+ let state_hash =
+ FastInsecureHasher::hash(serde_json::to_string(state).unwrap());
let sql_cache = SqlIncrementalCache::new(db, state_hash);
Self::from_sql_incremental_cache(sql_cache, initial_file_paths)
}
@@ -114,15 +113,13 @@ impl IncrementalCacheInner {
pub fn is_file_same(&self, file_path: &Path, file_text: &str) -> bool {
match self.previous_hashes.get(file_path) {
- Some(hash) => {
- *hash == FastInsecureHasher::new().write_str(file_text).finish()
- }
+ Some(hash) => *hash == FastInsecureHasher::hash(file_text),
None => false,
}
}
pub fn update_file(&self, file_path: &Path, file_text: &str) {
- let hash = FastInsecureHasher::new().write_str(file_text).finish();
+ let hash = FastInsecureHasher::hash(file_text);
if let Some(previous_hash) = self.previous_hashes.get(file_path) {
if *previous_hash == hash {
return; // do not bother updating the db file because nothing has changed
@@ -270,7 +267,7 @@ mod test {
let sql_cache = SqlIncrementalCache::new(conn, 1);
let file_path = PathBuf::from("/mod.ts");
let file_text = "test";
- let file_hash = FastInsecureHasher::new().write_str(file_text).finish();
+ let file_hash = FastInsecureHasher::hash(file_text);
sql_cache.set_source_hash(&file_path, file_hash).unwrap();
let cache = IncrementalCacheInner::from_sql_incremental_cache(
sql_cache,
diff --git a/cli/cache/node.rs b/cli/cache/node.rs
index 298d81e2f..825bdfef4 100644
--- a/cli/cache/node.rs
+++ b/cli/cache/node.rs
@@ -49,10 +49,7 @@ impl NodeAnalysisCache {
}
pub fn compute_source_hash(text: &str) -> String {
- FastInsecureHasher::new()
- .write_str(text)
- .finish()
- .to_string()
+ FastInsecureHasher::hash(text).to_string()
}
fn ensure_ok<T: Default>(res: Result<T, AnyError>) -> T {
diff --git a/cli/cache/parsed_source.rs b/cli/cache/parsed_source.rs
index 6f9c2f38f..e231753d5 100644
--- a/cli/cache/parsed_source.rs
+++ b/cli/cache/parsed_source.rs
@@ -262,7 +262,7 @@ impl deno_graph::ModuleAnalyzer for ParsedSourceCacheModuleAnalyzer {
}
fn compute_source_hash(bytes: &[u8]) -> String {
- FastInsecureHasher::new().write(bytes).finish().to_string()
+ FastInsecureHasher::hash(bytes).to_string()
}
#[cfg(test)]