mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
try stack allocation for small vectors
This commit is contained in:
parent
8d668514e4
commit
2d0d54e13e
3 changed files with 38 additions and 6 deletions
|
@ -420,7 +420,7 @@ fn solve(
|
|||
);
|
||||
|
||||
// Add a variable for each def to new_vars_by_env.
|
||||
let mut local_def_vars = Vec::with_capacity(let_con.def_types.len());
|
||||
let mut local_def_vars = LocalDefVarsVec::with_length(let_con.def_types.len());
|
||||
|
||||
for (symbol, loc_type) in let_con.def_types.iter() {
|
||||
let var = type_to_var(subs, rank, pools, cached_aliases, &loc_type.value);
|
||||
|
@ -457,8 +457,8 @@ fn solve(
|
|||
ret_con,
|
||||
);
|
||||
|
||||
for (symbol, loc_var) in local_def_vars {
|
||||
check_for_infinite_type(subs, problems, symbol, loc_var);
|
||||
for (symbol, loc_var) in local_def_vars.iter() {
|
||||
check_for_infinite_type(subs, problems, *symbol, *loc_var);
|
||||
}
|
||||
|
||||
new_state
|
||||
|
@ -497,7 +497,7 @@ fn solve(
|
|||
// run solver in next pool
|
||||
|
||||
// Add a variable for each def to local_def_vars.
|
||||
let mut local_def_vars = Vec::with_capacity(let_con.def_types.len());
|
||||
let mut local_def_vars = LocalDefVarsVec::with_length(let_con.def_types.len());
|
||||
|
||||
for (symbol, loc_type) in let_con.def_types.iter() {
|
||||
let def_type = &loc_type.value;
|
||||
|
@ -615,8 +615,8 @@ fn solve(
|
|||
ret_con,
|
||||
);
|
||||
|
||||
for (symbol, loc_var) in local_def_vars {
|
||||
check_for_infinite_type(subs, problems, symbol, loc_var);
|
||||
for (symbol, loc_var) in local_def_vars.iter() {
|
||||
check_for_infinite_type(subs, problems, *symbol, *loc_var);
|
||||
}
|
||||
|
||||
new_state
|
||||
|
@ -626,6 +626,36 @@ fn solve(
|
|||
}
|
||||
}
|
||||
|
||||
enum LocalDefVarsVec<T> {
|
||||
Stack(arrayvec::ArrayVec<T, 32>),
|
||||
Heap(Vec<T>),
|
||||
}
|
||||
|
||||
impl<T> LocalDefVarsVec<T> {
|
||||
#[inline(always)]
|
||||
fn with_length(length: usize) -> Self {
|
||||
if length <= 32 {
|
||||
Self::Stack(Default::default())
|
||||
} else {
|
||||
Self::Heap(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&mut self, element: T) {
|
||||
match self {
|
||||
LocalDefVarsVec::Stack(vec) => vec.push(element),
|
||||
LocalDefVarsVec::Heap(vec) => vec.push(element),
|
||||
}
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &T> {
|
||||
match self {
|
||||
LocalDefVarsVec::Stack(vec) => vec.iter(),
|
||||
LocalDefVarsVec::Heap(vec) => vec.iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use std::cell::RefCell;
|
||||
std::thread_local! {
|
||||
/// Scratchpad arena so we don't need to allocate a new one all the time
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue