Skip to content

Commit

Permalink
chore: Optmize update_acir() (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-000 authored Sep 6, 2023
1 parent 747c604 commit e6c139b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/noirc_errors/src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use acvm::compiler::AcirTransformationMap;
use serde_with::serde_as;
use serde_with::DisplayFromStr;
use std::collections::BTreeMap;
use std::mem;

use crate::Location;
use serde::{Deserialize, Serialize};
Expand All @@ -29,16 +30,13 @@ impl DebugInfo {
/// renders the old `OpcodeLocation`s invalid. The AcirTransformationMap is able to map the old `OpcodeLocation` to the new ones.
/// Note: One old `OpcodeLocation` might have transformed into more than one new `OpcodeLocation`.
pub fn update_acir(&mut self, update_map: AcirTransformationMap) {
let mut new_locations_map = BTreeMap::new();
let old_locations = mem::take(&mut self.locations);

for (old_opcode_location, source_locations) in &self.locations {
let new_opcode_locations = update_map.new_locations(*old_opcode_location);
for new_opcode_location in new_opcode_locations {
new_locations_map.insert(new_opcode_location, source_locations.clone());
}
for (old_opcode_location, source_locations) in old_locations {
let _ = update_map.new_locations(old_opcode_location).map(|new_opcode_location| {
self.locations.insert(new_opcode_location, source_locations.clone());
});
}

self.locations = new_locations_map;
}

pub fn opcode_location(&self, loc: &OpcodeLocation) -> Option<Vec<Location>> {
Expand Down

0 comments on commit e6c139b

Please sign in to comment.