symbol table optimizations

This commit is contained in:
collin 2020-12-07 11:33:45 -05:00
parent 3b23eb595a
commit ed4e094377
3 changed files with 7 additions and 19 deletions

View File

@ -127,7 +127,9 @@ impl FunctionType {
pub fn num_inputs(&self) -> usize {
self.inputs
.iter()
.fold(0, |acc, function_input| acc + function_input.count())
.filter(|function_input| !function_input.is_self())
.count()
// .fold(0, |acc, function_input| acc + function_input.arguments())
}
///
@ -139,13 +141,10 @@ impl FunctionType {
}
///
/// Returns a vector of [&FunctionInputType] removing `self` and `mut self` inputs.
/// Returns an iterator of [&FunctionInputType] removing `self` and `mut self` inputs.
///
pub fn filter_self_inputs(&self) -> Vec<&FunctionInputType> {
self.inputs
.iter()
.filter(|input| !input.is_self())
.collect::<Vec<&FunctionInputType>>()
pub fn filter_self_inputs(&self) -> impl Iterator<Item = &FunctionInputType> {
self.inputs.iter().filter(|input| !input.is_self())
}
}

View File

@ -77,15 +77,6 @@ impl FunctionInputType {
}
}
///
/// Returns `0` if the function input is a `self` or `mut self` keyword which does not have to
/// provided in a call to the function.
/// Returns `1` if a variable must be provided in a call to the function.
///
pub fn count(&self) -> usize {
if self.is_self() { 0 } else { 1 }
}
///
/// Return a new `FunctionInputType` from a given `FunctionInput`.
///

View File

@ -1120,10 +1120,8 @@ impl Frame {
}
// Filter out `self` and `mut self` keywords.
let expected_inputs = function_type.filter_self_inputs();
// Assert function inputs are correct types.
for (expected_input, actual_input) in expected_inputs.iter().zip(inputs) {
for (expected_input, actual_input) in function_type.filter_self_inputs().zip(inputs) {
// Parse expected input type.
let expected_type = expected_input.type_();