Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: grow memory when necessary in
BaseVec::set
. (#222)
## Problem `BaseVec`, which is the underlying data structure used by `StableVec` and `StableMinHeap` provides a `set` method that allows the caller to change the value of an element at a specified index. The `set` method used the `memory.write` method, which assumed that there is always enough memory to rewrite the element. This assumption would've been fine if other methods like `push` always allocated the maximum amount of space for every element. Currently though, `push` only allocates the amount needed to store the element that's being pushed. ## Solution There are two possible solutions: 1. Modify `push` to always allocate the maximum size of an element. 2. Modify `set` to grow the memory as needed as it's rewriting an element. This commit implements solution 2, which is both simpler and more performant.
- Loading branch information