Skip to content

Commit

Permalink
Merge pull request #153 from buty4649/more-speedup
Browse files Browse the repository at this point in the history
Remove BufferedIO due to performance issues, introduce new Reader class
  • Loading branch information
buty4649 authored Jan 26, 2024
2 parents 3aae5ea + 1d2415c commit d916f4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 62 deletions.
61 changes: 0 additions & 61 deletions mrblib/rf/buffered_io.rb

This file was deleted.

28 changes: 28 additions & 0 deletions mrblib/rf/reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Rf
class Reader
def initialize(file_name, mode = 'r')
@file = file_name == '-' ? $stdin : File.open(file_name, mode)
@binary = false
end

def binary?
@binary
end

def gets
line = @file.readline
@binary = true if /(?![\r\n\t])\p{Cntrl}/.match?(line)
line
rescue EOFError
nil
end

def read
@file.read
end

def close
@file.close
end
end
end
2 changes: 1 addition & 1 deletion mrblib/rf/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run # rubocop:disable Metrics/AbcSize
def read_open(file)
raise IsDirectory, file if File.directory?(file)

BufferedIO.new(file)
Reader.new(file)
rescue Errno::ENOENT
raise NotFound, file
rescue Errno::EACCES
Expand Down

0 comments on commit d916f4d

Please sign in to comment.