Skip to content

Commit

Permalink
Reduce memory usage while generating report
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and PragTob committed Apr 10, 2022
1 parent 5c737a3 commit efdb08d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(filename, coverage_data)

# The path to this source file relative to the projects directory
def project_filename
@filename.sub(Regexp.new("^#{Regexp.escape(SimpleCov.root)}"), "")
@filename.delete_prefix(SimpleCov.root)
end

# The source code for this file. Aliased as :source
Expand Down Expand Up @@ -217,7 +217,13 @@ def ensure_remove_undefs(file_lines)
# simplecov-html to have encoding shenaningans in one place. See #866
# also setting these option on `file.set_encoding` doesn't seem to work
# properly so it has to be done here.
file_lines.each { |line| line.encode!("UTF-8", invalid: :replace, undef: :replace) }
file_lines.each do |line|
if line.encoding == Encoding::UTF_8
line
else
line.encode!("UTF-8", invalid: :replace, undef: :replace)
end
end
end

def build_lines
Expand All @@ -238,7 +244,7 @@ def process_skipped_lines(lines)
end

def lines_strength
lines.map(&:coverage).compact.reduce(:+)
lines.sum { |line| line.coverage.to_i }
end

# Warning to identify condition from Issue #56
Expand Down

0 comments on commit efdb08d

Please sign in to comment.