Avoid using iterators and throw-away heap allocations

This commit is contained in:
fn ⌃ ⌥ 2021-10-27 11:08:18 -07:00
parent b7bb282b99
commit 73e97ac42e

View file

@ -4,11 +4,13 @@ class Ameba::Source
# This class takes source code and rewrites it based
# on the different correction actions supplied.
class Corrector
@line_sizes : Array(Int32)
@line_sizes = [] of Int32
def initialize(code : String)
code.each_line(chomp: false) do |line|
@line_sizes << line.size
end
@rewriter = Rewriter.new(code)
@line_sizes = code.each_line(chomp: false).map(&.size).to_a
end
# Replaces the code of the given range with *content*.