mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
some unsafe to make fewer clones
This commit is contained in:
parent
212f032e96
commit
c87f984d0a
1 changed files with 9 additions and 1 deletions
|
@ -1029,7 +1029,15 @@ fn adjust_rank(
|
|||
// Mark the variable as visited before adjusting content, as it may be cyclic.
|
||||
subs.set_mark(var, visit_mark);
|
||||
|
||||
let content = &subs.get_ref(var).content.clone();
|
||||
// SAFETY: in this function (and functions it calls, we ONLY modify rank and mark, never content!
|
||||
// hence, we can have an immutable reference to it even though we also have a mutable
|
||||
// reference to the Subs as a whole. This prevents a clone of the content, which turns out
|
||||
// to be quite expensive.
|
||||
let content = {
|
||||
let ptr = &subs.get_ref(var).content as *const _;
|
||||
unsafe { &*ptr }
|
||||
};
|
||||
|
||||
let max_rank = adjust_rank_content(subs, young_mark, visit_mark, group_rank, &content);
|
||||
|
||||
subs.set_rank_mark(var, max_rank, visit_mark);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue