Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop to read unused source code #540

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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