Skip to content

Commit 1d2415c

Browse files
committed
Remove BufferedIO due to performance issues, introduce new Reader class
1 parent 3aae5ea commit 1d2415c

File tree

3 files changed

+29
-62
lines changed

3 files changed

+29
-62
lines changed

mrblib/rf/buffered_io.rb

-61
This file was deleted.

mrblib/rf/reader.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Rf
2+
class Reader
3+
def initialize(file_name, mode = 'r')
4+
@file = file_name == '-' ? $stdin : File.open(file_name, mode)
5+
@binary = false
6+
end
7+
8+
def binary?
9+
@binary
10+
end
11+
12+
def gets
13+
line = @file.readline
14+
@binary = true if /(?![\r\n\t])\p{Cntrl}/.match?(line)
15+
line
16+
rescue EOFError
17+
nil
18+
end
19+
20+
def read
21+
@file.read
22+
end
23+
24+
def close
25+
@file.close
26+
end
27+
end
28+
end

mrblib/rf/runner.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def run # rubocop:disable Metrics/AbcSize
7777
def read_open(file)
7878
raise IsDirectory, file if File.directory?(file)
7979

80-
BufferedIO.new(file)
80+
Reader.new(file)
8181
rescue Errno::ENOENT
8282
raise NotFound, file
8383
rescue Errno::EACCES

0 commit comments

Comments
 (0)