Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize merging line coverage #1121

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Optimize merging line coverage
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).
splattael committed Jan 7, 2025
commit 1e36da1453722955128d1e4bcbc85f81baa60a6c
12 changes: 6 additions & 6 deletions lib/simplecov/combine/lines_combiner.rb
Original file line number Diff line number Diff line change
@@ -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