Commit 7cc8c7d2 authored by dearblue's avatar dearblue

Small improvement for mruby-io

parent 52a0ad41
...@@ -123,8 +123,8 @@ class IO ...@@ -123,8 +123,8 @@ class IO
def write(string) def write(string)
str = string.is_a?(String) ? string : string.to_s str = string.is_a?(String) ? string : string.to_s
return str.size unless str.size > 0 return 0 if str.empty?
if 0 < @buf.length unless @buf.empty?
# reset real pos ignore buf # reset real pos ignore buf
seek(pos, SEEK_SET) seek(pos, SEEK_SET)
end end
...@@ -141,7 +141,7 @@ class IO ...@@ -141,7 +141,7 @@ class IO
_check_readable _check_readable
begin begin
buf = _read_buf buf = _read_buf
return buf.size == 0 return buf.empty?
rescue EOFError rescue EOFError
return true return true
end end
...@@ -170,7 +170,7 @@ class IO ...@@ -170,7 +170,7 @@ class IO
end end
def _read_buf def _read_buf
return @buf if @buf && @buf.size > 0 return @buf if @buf && @buf.bytesize > 0
@buf = sysread(BUF_SIZE) @buf = sysread(BUF_SIZE)
end end
...@@ -255,12 +255,12 @@ class IO ...@@ -255,12 +255,12 @@ class IO
if limit && limit <= @buf.size if limit && limit <= @buf.size
array.push @buf[0, limit] array.push @buf[0, limit]
@buf = @buf[limit, @buf.size - limit] @buf[0, limit] = ""
break break
elsif idx = @buf.index(rs) elsif idx = @buf.index(rs)
len = idx + rs.size len = idx + rs.size
array.push @buf[0, len] array.push @buf[0, len]
@buf = @buf[len, @buf.size - len] @buf[0, len] = ""
break break
else else
array.push @buf array.push @buf
...@@ -284,7 +284,7 @@ class IO ...@@ -284,7 +284,7 @@ class IO
def readchar def readchar
_read_buf _read_buf
c = @buf[0] c = @buf[0]
@buf = @buf[1, @buf.size] @buf[0] = ""
c c
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment