Skip to content

Commit

Permalink
apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Feb 3, 2025
1 parent 94c7d01 commit 26b9eb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/e2e-move-tests/src/tests/move_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use initia_move_types::metadata;

use move_cli::base::test::{run_move_unit_tests_with_factory, UnitTestResult};
use move_core_types::effects::ChangeSet;
use move_model::metadata::{CompilerVersion, LanguageVersion};
use move_unit_test::UnitTestingConfig;
use move_vm_runtime::native_extensions::NativeContextExtensions;
use move_model::metadata::{CompilerVersion, LanguageVersion};

use once_cell::sync::Lazy;
use std::path::PathBuf;
Expand Down
26 changes: 11 additions & 15 deletions crates/storage/src/script_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub struct InitiaScriptCache {

impl InitiaScriptCache {
pub fn new(cache_capacity: usize) -> Arc<InitiaScriptCache> {
let capacity = cache_capacity * 1024 * 1024;
Arc::new(InitiaScriptCache {
capacity: cache_capacity * 1024 * 1024,
capacity,
script_cache: Mutex::new(CLruCache::with_config(
CLruCacheConfig::new(NonZeroUsize::new(cache_capacity * 1024 * 1024).unwrap())
.with_scale(ScriptScale),
CLruCacheConfig::new(NonZeroUsize::new(capacity).unwrap()).with_scale(ScriptScale),
)),
})
}
Expand All @@ -45,13 +45,11 @@ impl InitiaScriptCache {
let deserialized_script = new_script.deserialized().clone();

if self.capacity >= allocated_size {
script_cache
// NOTE: We are not handling the error here, because we are sure that the
// allocated size is less than the capacity.
let _ = script_cache
.put_with_weight(key, ScriptWrapper::new(new_script, allocated_size))
.unwrap_or_else(|_| {
// ignore cache errors
eprintln!("WARNING: failed to insert script into cache");
None
});
.unwrap_or_else(|_| None);
}

Ok(deserialized_script)
Expand Down Expand Up @@ -86,13 +84,11 @@ impl InitiaScriptCache {

if let Some(new_script) = new_script {
if self.capacity >= allocated_size {
script_cache
// NOTE: We are not handling the error here, because we are sure that the
// allocated size is less than the capacity.
let _ = script_cache
.put_with_weight(key, ScriptWrapper::new(new_script, allocated_size))
.unwrap_or_else(|_| {
// ignore cache errors
eprintln!("WARNING: failed to insert script into cache");
None
});
.unwrap_or_else(|_| None);
}
}
Ok(verified_script)
Expand Down

0 comments on commit 26b9eb2

Please sign in to comment.