diff --git a/CHANGELOG.md b/CHANGELOG.md index 149ea37828..31c24f4024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ #### Upcoming Changes -* Add `CairoRunner::get_program method` [#1123](https://github.com/lambdaclass/cairo-rs/pull/1123): +* perf: insert elements from the tail in `load_data` so reallocation happens only once [#1117](https://github.com/lambdaclass/cairo-rs/pull/1117) + +* Add `CairoRunner::get_program method` [#1123](https://github.com/lambdaclass/cairo-rs/pull/1123) * Use to_signed_felt as function for felt252 as BigInt within [-P/2, P/2] range and use to_bigint as function for representation as BigInt. [#1100](https://github.com/lambdaclass/cairo-rs/pull/1100) diff --git a/src/vm/vm_memory/memory_segments.rs b/src/vm/vm_memory/memory_segments.rs index 5fdda00126..c6c91221ed 100644 --- a/src/vm/vm_memory/memory_segments.rs +++ b/src/vm/vm_memory/memory_segments.rs @@ -55,7 +55,9 @@ impl MemorySegmentManager { ptr: Relocatable, data: &Vec, ) -> Result { - for (num, value) in data.iter().enumerate() { + // Starting from the end ensures any necessary resize + // is performed once with enough room for everything + for (num, value) in data.iter().enumerate().rev() { self.memory.insert((ptr + num)?, value)?; } (ptr + data.len()).map_err(MemoryError::Math)