Skip to content

Commit

Permalink
Move metrics sum computation into a new function
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannitangredi authored and Luni-4 committed Mar 4, 2022
1 parent 7c21e14 commit ec0183a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/metrics/cognitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ impl Stats {
pub fn cognitive_average(&self) -> f64 {
self.cognitive_sum() / self.total_space_functions as f64
}
#[inline(always)]
pub(crate) fn compute_sum(&mut self) {
self.structural_sum += self.structural;
}
pub(crate) fn compute_minmax(&mut self) {
self.structural_min = self.structural_min.min(self.structural);
self.structural_max = self.structural_max.max(self.structural);
self.structural_sum += self.structural;
self.compute_sum();
}

pub(crate) fn finalize(&mut self, total_space_functions: usize) {
Expand Down
6 changes: 5 additions & 1 deletion src/metrics/cyclomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ impl Stats {
pub fn cyclomatic_min(&self) -> f64 {
self.cyclomatic_min
}
#[inline(always)]
pub(crate) fn compute_sum(&mut self) {
self.cyclomatic_sum += self.cyclomatic;
}
pub(crate) fn compute_minmax(&mut self) {
self.cyclomatic_max = self.cyclomatic_max.max(self.cyclomatic);
self.cyclomatic_min = self.cyclomatic_min.min(self.cyclomatic);
self.cyclomatic_sum += self.cyclomatic;
self.compute_sum();
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/metrics/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ impl Stats {
pub fn exit_average(&self) -> f64 {
self.exit_sum() / self.total_space_functions as f64
}
#[inline(always)]
pub(crate) fn compute_sum(&mut self) {
self.exit_sum += self.exit;
}
pub(crate) fn compute_minmax(&mut self) {
self.exit_max = self.exit_max.max(self.exit);
self.exit_min = self.exit_min.min(self.exit);
self.exit_sum += self.exit;
self.compute_sum();
}
pub(crate) fn finalize(&mut self, total_space_functions: usize) {
self.total_space_functions = total_space_functions;
Expand Down
9 changes: 6 additions & 3 deletions src/metrics/nargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,17 @@ impl Stats {
pub fn closure_args_max(&self) -> f64 {
self.closure_nargs_max as f64
}

#[inline(always)]
pub(crate) fn compute_sum(&mut self) {
self.closure_nargs_sum += self.closure_nargs;
self.fn_nargs_sum += self.fn_nargs;
}
pub(crate) fn compute_minmax(&mut self) {
self.closure_nargs_min = self.closure_nargs_min.min(self.closure_nargs);
self.closure_nargs_max = self.closure_nargs_max.max(self.closure_nargs);
self.fn_nargs_min = self.fn_nargs_min.min(self.fn_nargs);
self.fn_nargs_max = self.fn_nargs_max.max(self.fn_nargs);
self.closure_nargs_sum += self.closure_nargs;
self.fn_nargs_sum += self.fn_nargs;
self.compute_sum();
}
pub(crate) fn finalize(&mut self, total_functions: usize, total_closures: usize) {
self.total_functions = total_functions;
Expand Down
8 changes: 6 additions & 2 deletions src/metrics/nom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ impl Stats {
pub fn total(&self) -> f64 {
self.functions_sum() + self.closures_sum()
}
#[inline(always)]
pub(crate) fn compute_sum(&mut self) {
self.functions_sum += self.functions;
self.closures_sum += self.closures;
}
pub(crate) fn compute_minmax(&mut self) {
self.functions_min = self.functions_min.min(self.functions);
self.functions_max = self.functions_max.max(self.functions);
self.closures_min = self.closures_min.min(self.closures);
self.closures_max = self.closures_max.max(self.closures);
self.functions_sum += self.functions;
self.closures_sum += self.closures;
self.compute_sum();
}
}

Expand Down

0 comments on commit ec0183a

Please sign in to comment.