Skip to content

Commit e284753

Browse files
authored
perf: eager resize for ´load_data´ (#1117)
1 parent c035797 commit e284753

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#### Upcoming Changes
44

5-
* Add `CairoRunner::get_program method` [#1123](https://github.com/lambdaclass/cairo-rs/pull/1123):
5+
* perf: insert elements from the tail in `load_data` so reallocation happens only once [#1117](https://github.com/lambdaclass/cairo-rs/pull/1117)
6+
7+
* Add `CairoRunner::get_program method` [#1123](https://github.com/lambdaclass/cairo-rs/pull/1123)
68

79
* 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)
810

src/vm/vm_memory/memory_segments.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ impl MemorySegmentManager {
5555
ptr: Relocatable,
5656
data: &Vec<MaybeRelocatable>,
5757
) -> Result<Relocatable, MemoryError> {
58-
for (num, value) in data.iter().enumerate() {
58+
// Starting from the end ensures any necessary resize
59+
// is performed once with enough room for everything
60+
for (num, value) in data.iter().enumerate().rev() {
5961
self.memory.insert((ptr + num)?, value)?;
6062
}
6163
(ptr + data.len()).map_err(MemoryError::Math)

0 commit comments

Comments
 (0)