Skip to content

Commit 39c7de1

Browse files
committed
Cache whether SimpleCov has/had branch coverage enabled
We make the check sooooo many times that I feel better having it cached especially when it doesn't make the code more complex and when it also is unlikely to change while the formatter is running (read: it shouldn't change then)
1 parent 1e2605c commit 39c7de1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/simplecov-html.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
module SimpleCov
1717
module Formatter
1818
class HTMLFormatter
19+
def initialize
20+
@branchable_result = SimpleCov.branch_coverage?
21+
end
22+
1923
def format(result)
2024
Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
2125
FileUtils.cp_r(path, asset_output_path)
@@ -31,10 +35,11 @@ def output_message(result)
3135
"Coverage report generated for #{result.command_name} to #{output_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
3236
end
3337

34-
# Check if branchable results supported or not
35-
# Try used here to escape exceptions
3638
def branchable_result?
37-
SimpleCov.branch_coverage?
39+
# cached in initialize because we truly look it up a whole bunch of times
40+
# and it's easier to cache here then in SimpleCov because there we might
41+
# still enable/disable branch coverage criterion
42+
@branchable_result
3843
end
3944

4045
def line_status?(source_file, line)

0 commit comments

Comments
 (0)