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 all commits
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
20 changes: 9 additions & 11 deletions lib/simplecov/combine/lines_combiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ module LinesCombiner
module_function

def combine(coverage_a, coverage_b)
coverage_a
.zip(coverage_b)
.map do |coverage_a_val, coverage_b_val|
merge_line_coverage(coverage_a_val, coverage_b_val)
end
coverage_a.map.with_index do |coverage_a_val, index|
merge_line_coverage(coverage_a_val, coverage_b[index])
end
end

# Return depends on coverage in a specific line
Expand All @@ -30,12 +28,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
Loading