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/emit.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/emit.rs')
-rw-r--r-- | cli/cache/emit.rs | 12 |
1 files changed, 6 insertions, 6 deletions
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)); |