mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
remove extra lookup
This commit is contained in:
parent
7d0c1f5787
commit
204aa6f88a
1 changed files with 25 additions and 18 deletions
|
@ -344,6 +344,25 @@ impl<'a> BorrowInfState<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// if the extracted value is owned, then the surrounding structure must be too
|
||||
fn if_is_owned_then_own(&mut self, extracted: Symbol, structure: Symbol) {
|
||||
match self.owned.get_mut(&self.current_proc) {
|
||||
None => unreachable!(
|
||||
"the current procedure symbol {:?} is not in the owned map",
|
||||
self.current_proc
|
||||
),
|
||||
Some(set) => {
|
||||
if set.contains(&extracted) {
|
||||
if set.insert(structure) {
|
||||
// entered if key was not yet present. If so, the set is modified,
|
||||
// hence we set this flag
|
||||
self.modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_owned(&self, x: Symbol) -> bool {
|
||||
match self.owned.get(&self.current_proc) {
|
||||
None => unreachable!(
|
||||
|
@ -690,38 +709,26 @@ impl<'a> BorrowInfState<'a> {
|
|||
|
||||
StructAtIndex { structure: x, .. } => {
|
||||
// if the structure (record/tag/array) is owned, the extracted value is
|
||||
if self.is_owned(*x) {
|
||||
self.own_var(z);
|
||||
}
|
||||
self.if_is_owned_then_own(*x, z);
|
||||
|
||||
// if the extracted value is owned, the structure must be too
|
||||
if self.is_owned(z) {
|
||||
self.own_var(*x);
|
||||
}
|
||||
self.if_is_owned_then_own(z, *x);
|
||||
}
|
||||
|
||||
UnionAtIndex { structure: x, .. } => {
|
||||
// if the structure (record/tag/array) is owned, the extracted value is
|
||||
if self.is_owned(*x) {
|
||||
self.own_var(z);
|
||||
}
|
||||
self.if_is_owned_then_own(*x, z);
|
||||
|
||||
// if the extracted value is owned, the structure must be too
|
||||
if self.is_owned(z) {
|
||||
self.own_var(*x);
|
||||
}
|
||||
self.if_is_owned_then_own(z, *x);
|
||||
}
|
||||
|
||||
GetTagId { structure: x, .. } => {
|
||||
// if the structure (record/tag/array) is owned, the extracted value is
|
||||
if self.is_owned(*x) {
|
||||
self.own_var(z);
|
||||
}
|
||||
self.if_is_owned_then_own(*x, z);
|
||||
|
||||
// if the extracted value is owned, the structure must be too
|
||||
if self.is_owned(z) {
|
||||
self.own_var(*x);
|
||||
}
|
||||
self.if_is_owned_then_own(z, *x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue