Skip to content

Commit

Permalink
Merge pull request #540 from yui-knk/speed_up
Browse files Browse the repository at this point in the history
Stop to read unused source code
  • Loading branch information
colszowka committed Jan 24, 2017
2 parents 9912a0d + aa79915 commit b94d93b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,20 @@ 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
# We intentionally read source code lazily to
# suppress reading unused source code.
@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 b94d93b

Please sign in to comment.