Double unwrap for `program_base` in Cairo runner `initialize_state`
tcoratger opened this issue · comments
Issue Description
In the initialize_state
function of the CairoRunner
structure, there is redundant code in my opinion, that can be improved for clarity and efficiency.
At the beginning of the function, there is a conditional check (if let Some(prog_base) = self.program_base
) to ensure that self.program_base
is not None
.
cairo-vm/vm/src/vm/runners/cairo_runner.rs
Lines 414 to 431 in 4ea224a
However, a few lines later, the unwrap
method is used again on self.program_base
to obtain base
, and in case of None
, it sets base
to Relocatable::from((0, 0))
.
cairo-vm/vm/src/vm/runners/cairo_runner.rs
Lines 425 to 427 in 4ea224a
This redundant check and assignment can be eliminated because the None
case will never happen inside the if
statement, making the base
declaration unnecessary. Instead, we can directly use the prog_base
variable in the loop to mark memory segments as accessed.