Skip to content

Commit

Permalink
Stop to read unused source code
Browse files Browse the repository at this point in the history
Before this commit all source code were loaded, even if
they are not used.
For example when taking test coverage for rails applications,
in many cases files on "vendor/bundle" are filtered out.
By reading source code lazily, the time required to generate
results will be shortened.
  • Loading branch information
yui-knk committed Dec 13, 2016
1 parent a8a8c26 commit 204abc4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ def status
attr_reader :filename
# The array of coverage data received from the Coverage.result
attr_reader :coverage
# The source code for this file. Aliased as :source
attr_reader :src
alias source src

def initialize(filename, coverage)
@filename = filename
@coverage = coverage
File.open(filename, "rb") { |f| @src = f.readlines }
end

# The source code for this file. Aliased as :source
def src
@src ||= File.open(filename, "rb", &:readlines)
end
alias source src

# Returns all source lines for this file as instances of SimpleCov::SourceFile::Line,
# and thus including coverage data. Aliased as :source_lines
def lines
Expand Down

0 comments on commit 204abc4

Please sign in to comment.