Skip to content

Commit 15c03b2

Browse files
committed
optimize result merger
1 parent ddccb3c commit 15c03b2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/simplecov/result_merger.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ def merge_results(*file_paths, ignore_timeout: false)
3232
# of data. Reading them all in easily produces Gigabytes of memory consumption which
3333
# we want to avoid.
3434

35-
results = file_paths.map { |path| valid_results(path, ignore_timeout: ignore_timeout) }
36-
merge_coverage(results)
35+
file_paths = file_paths.dup
36+
initial_result = merge_file_results(file_paths.shift, ignore_timeout: ignore_timeout)
37+
38+
file_paths.reduce(initial_result) do |memo, path|
39+
file_result = merge_file_results(path, ignore_timeout: ignore_timeout)
40+
merge_coverage([memo, file_result])
41+
end
3742
end
3843

39-
def valid_results(file_path, ignore_timeout: false)
44+
def merge_file_results(file_path, ignore_timeout:)
4045
raw_results = parse_file(file_path)
4146
results = Result.from_hash(raw_results)
4247
merge_valid_results(results, ignore_timeout: ignore_timeout)

lib/simplecov/result_serialization.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def deserialize(hash) # rubocop:disable Metrics/MethodLength
2424
hash.map do |command_name, data|
2525
coverage = {}
2626

27-
data["coverage"].each do |file_name, file_data|
27+
data.fetch("coverage").each do |file_name, file_data|
2828
parsed_file_data = {}
2929

3030
file_data = {lines: file_data} if file_data.is_a?(Array)
@@ -39,7 +39,7 @@ def deserialize(hash) # rubocop:disable Metrics/MethodLength
3939

4040
result = SimpleCov::Result.new(coverage)
4141
result.command_name = command_name
42-
result.created_at = Time.at(data["timestamp"])
42+
result.created_at = Time.at(data.fetch("timestamp"))
4343
result
4444
end
4545
end

0 commit comments

Comments
 (0)