stable-structures
stable-structures copied to clipboard
Add StableVec::extend method
Currently the only way to extend a StableVec with another vector or slice is repeatedly calling push:
let stable_vec = StableVec::<u8, _>::init(mem).expect("Memory was not for stable vec");
let bytes = bincode::encode_to_vec(value, BINCODE_CONFIG).expect("Failed to serialize value");
for byte in bytes {
stable_vec.push(&byte).expect("StableVec push failed");
}
The above code is very memory inefficient as it requires running the entire push code for every element (including growing memory!).
A similar method already exists for the std Vec: Vec::extend
Growing the memory is amortized, so I'm not sure if this would result in a significant performance improvement. But we'd be open to the idea if you want to try it out.