From b69bc5325a83c189cdcd76b1c2d8dd064b29c13b Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 11 Jun 2008 14:54:23 +0000 Subject: * io.c (io_fread): bypass buffered read if reading buffer is empty. * io.c (remain_size): do not add extra one byte. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@17098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ io.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7a0efbcae..7a50c3401 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jun 11 23:33:13 2008 Yukihiro Matsumoto + + * io.c (io_fread): bypass buffered read if reading buffer is empty. + + * io.c (remain_size): do not add extra one byte. + Wed Jun 11 12:15:17 2008 Tanaka Akira * bootstraptest/runner.rb (assert_normal_exit): hide stderr output diff --git a/io.c b/io.c index d5ffa0cf6..ced6a7aed 100644 --- a/io.c +++ b/io.c @@ -1298,6 +1298,20 @@ io_fread(VALUE str, long offset, rb_io_t *fptr) long n = len; int c; + if (READ_DATA_PENDING(fptr) == 0) { + while (n > 0) { + c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n); + if (c == 0) break; + if (c < 0) { + rb_sys_fail(fptr->path); + } + offset += c; + if ((n -= c) <= 0) break; + rb_thread_wait_fd(fptr->fd); + } + return len - n; + } + while (n > 0) { c = read_buffered_data(RSTRING_PTR(str)+offset, n, fptr); if (c > 0) { @@ -1347,7 +1361,7 @@ remain_size(rb_io_t *fptr) io_fflush(fptr); pos = lseek(fptr->fd, 0, SEEK_CUR); if (st.st_size >= pos && pos >= 0) { - siz += st.st_size - pos + 1; + siz += st.st_size - pos; if (siz > LONG_MAX) { rb_raise(rb_eIOError, "file too big for single read"); } -- cgit