Skip to content

Commit

Permalink
Optimize merging line coverage
Browse files Browse the repository at this point in the history
Prior this change `Integer#to_i` and `NilClass#to_i` showed up in
stack profiler which resulted to slow down `merge_line_coverage` a lot.

This change brought down the run time from 1m28s to 1m18s on a large
resultset (GitLab).
  • Loading branch information
splattael committed Jan 7, 2025
1 parent b6c2d42 commit 1e36da1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/simplecov/combine/lines_combiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def combine(coverage_a, coverage_b)
#
# @return [Integer || nil]
def merge_line_coverage(first_val, second_val)
sum = first_val.to_i + second_val.to_i

if sum.zero? && (first_val.nil? || second_val.nil?)
nil
else
sum
if first_val && second_val
first_val + second_val
elsif first_val
first_val.zero? ? nil : first_val
elsif second_val
second_val.zero? ? nil : second_val
end
end
end
Expand Down

0 comments on commit 1e36da1

Please sign in to comment.