Module: SimpleCov::Combine::BranchesCombiner
- Extended by:
- BranchesCombiner
- Included in:
- BranchesCombiner
- Defined in:
- lib/simplecov/combine/branches_combiner.rb
Instance Method Summary collapse
-
#absorb(target, coverage) ⇒ Object
Folds
coverageintotarget, an interned table keyed by condition identity. - #combine(coverage_a, coverage_b) ⇒ Object
- #identities ⇒ Object
-
#materialize(target) ⇒ Object
Turns an interned table back into the tuple-keyed hash the rest of SimpleCov reads.
- #new_condition(condition) ⇒ Object
-
#tuple_identity(tuple) ⇒ Object
Branches match on source span, whatever ids the recording processes handed them (#1233).
Instance Method Details
#absorb(target, coverage) ⇒ Object
Folds coverage into target, an interned table keyed by condition
identity. Kept interned rather than turned back into tuple keys per merge,
so a fold over N resultsets interns each condition once instead of
re-interning the whole accumulated table N times.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simplecov/combine/branches_combiner.rb', line 21 def absorb(target, coverage) return target unless coverage coverage.each do |condition, branches_inside| entry = target[identities[condition]] ||= new_condition(condition) InternedCounts.absorb_counts(entry.fetch(1), branches_inside, identities) end target end |
#combine(coverage_a, coverage_b) ⇒ Object
12 13 14 15 |
# File 'lib/simplecov/combine/branches_combiner.rb', line 12 def combine(coverage_a, coverage_b) merged = absorb({}, coverage_a) #: Hash[untyped, [untyped, Hash[untyped, untyped]]] materialize(absorb(merged, coverage_b)) end |
#identities ⇒ Object
43 44 45 |
# File 'lib/simplecov/combine/branches_combiner.rb', line 43 def identities @identities ||= IdentityInterner.build { |tuple| tuple_identity(tuple) } end |
#materialize(target) ⇒ Object
Turns an interned table back into the tuple-keyed hash the rest of SimpleCov reads. Done once, at the end of a fold.
39 40 41 |
# File 'lib/simplecov/combine/branches_combiner.rb', line 39 def materialize(target) target.values.to_h { |condition, branches| [condition, branches.values.to_h] } end |
#new_condition(condition) ⇒ Object
32 33 34 35 |
# File 'lib/simplecov/combine/branches_combiner.rb', line 32 def new_condition(condition) arms = {} #: Hash[untyped, untyped] [condition, arms] end |
#tuple_identity(tuple) ⇒ Object
Branches match on source span, whatever ids the recording processes handed them (#1233).
49 50 51 52 |
# File 'lib/simplecov/combine/branches_combiner.rb', line 49 def tuple_identity(tuple) type, _id, start_line, start_column, end_line, end_column = SourceFile::RubyDataParser.call(tuple) [type, start_line, start_column, end_line, end_column].freeze end |