Merge pull request #8 from arthurschreiber/arthur/reduce-mem-usage

Don't use a StringIO when encoding data.
This commit is contained in:
Carlos Martín Nieto 2016-08-12 12:23:38 +02:00 коммит произвёл GitHub
Родитель c489ecd510 55cacadf2e
Коммит 3edcf493b0
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -62,6 +62,10 @@ module BERT
@buf.each { |x| io.write x } @buf.each { |x| io.write x }
end end
def to_s
@buf.join("")
end
def bytesize def bytesize
@buf.map(&:bytesize).inject :+ @buf.map(&:bytesize).inject :+
end end
@ -74,11 +78,7 @@ module BERT
end end
def self.encode(data) def self.encode(data)
buf = encode_to_buffer data encode_to_buffer(data).to_s
io = StringIO.new
io.set_encoding('binary') if io.respond_to?(:set_encoding)
buf.write_to io
io.string
end end
def self.encode_data(data, io) def self.encode_data(data, io)