Class: Bychar::ReaderIOBuf
- Inherits:
-
Object
- Object
- Bychar::ReaderIOBuf
- Defined in:
- lib/impls/reader_iobuf.rb
Instance Method Summary collapse
-
#initialize(with_io, buffer_size = DEFAULT_BUFFER_SIZE) ⇒ ReaderIOBuf
constructor
A new instance of ReaderIOBuf.
-
#read_one_char ⇒ Object
Since you parse char by char, you will be tempted to do it in a tight loop and to call eof? on each iteration.
Constructor Details
#initialize(with_io, buffer_size = DEFAULT_BUFFER_SIZE) ⇒ ReaderIOBuf
Returns a new instance of ReaderIOBuf.
4 5 6 7 8 |
# File 'lib/impls/reader_iobuf.rb', line 4 def initialize(with_io, buffer_size = DEFAULT_BUFFER_SIZE) @io = with_io @bufsize = buffer_size cache end |
Instance Method Details
#read_one_char ⇒ Object
Since you parse char by char, you will be tempted to do it in a tight loop and to call eof? on each iteration. Don’t. Instead. allow it to raise and do not check. This takes the profile time down from 36 seconds to 30 seconds for a large file.
13 14 15 16 17 18 |
# File 'lib/impls/reader_iobuf.rb', line 13 def read_one_char cache if @buf.eos? return nil if @buf.eos? @buf.getch end |