Skip to content

Commit

Permalink
Merge pull request #2409 from demergent-labs/stable_structures_no_arr…
Browse files Browse the repository at this point in the history
…ay_access

remove direct array accesses in experimental stable structures
  • Loading branch information
lastmjs authored Dec 31, 2024
2 parents f9b9249 + ef29773 commit b046c7a
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 7 deletions.
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ impl JsFn for NativeFunction {
.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();

stable_b_tree_maps[&memory_id].contains_key(&AzleStableBTreeMapKey { bytes: key })
stable_b_tree_maps
.get(&memory_id)
.unwrap()
.contains_key(&AzleStableBTreeMapKey { bytes: key })
})
.into()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl JsFn for NativeFunction {
let value_option = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();

stable_b_tree_maps[&memory_id].get(&AzleStableBTreeMapKey { bytes: key })
stable_b_tree_maps
.get(&memory_id)
.unwrap()
.get(&AzleStableBTreeMapKey { bytes: key })
});

// TODO could we somehow encode the entire option here more easily
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl JsFn for NativeFunction {
.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();

stable_b_tree_maps[&memory_id].is_empty()
stable_b_tree_maps.get(&memory_id).unwrap().is_empty()
})
.into()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl JsFn for NativeFunction {

let items: Vec<Vec<Vec<u8>>> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();
let stable_b_tree_map = &stable_b_tree_maps[&memory_id];
let stable_b_tree_map = stable_b_tree_maps.get(&memory_id).unwrap();

stable_b_tree_map
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl JsFn for NativeFunction {

let keys: Vec<Vec<u8>> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();
let stable_b_tree_map = &stable_b_tree_maps[&memory_id];
let stable_b_tree_map = stable_b_tree_maps.get(&memory_id).unwrap();

stable_b_tree_map
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl JsFn for NativeFunction {
let len = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();

stable_b_tree_maps[&memory_id].len()
stable_b_tree_maps.get(&memory_id).unwrap().len()
});

context.new_string(&len.to_string()).into()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl JsFn for NativeFunction {

let values: Vec<Vec<u8>> = STABLE_B_TREE_MAPS.with(|stable_b_tree_maps| {
let stable_b_tree_maps = stable_b_tree_maps.borrow();
let stable_b_tree_map = &stable_b_tree_maps[&memory_id];
let stable_b_tree_map = stable_b_tree_maps.get(&memory_id).unwrap();

stable_b_tree_map
.iter()
Expand Down

0 comments on commit b046c7a

Please sign in to comment.