diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-13 08:51:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-13 08:51:25 +0000 |
commit | dfd0cbece066cd992981607524426b36050cfb2c (patch) | |
tree | 6d4faf69d55120aaa8cdfdfcbad303f33a04cd00 /io.c | |
parent | 9f2e85a33c47493b2c58a98ab890ae1ee86b453a (diff) |
io.c: simplify
* io.c (rb_io_getline_fast, rb_io_each_{byte,codepoint}): simplify
loops.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -2849,7 +2849,7 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io) long pos = 0; int cr = 0; - for (;;) { + do { int pending = READ_DATA_PENDING_COUNT(fptr); if (pending > 0) { @@ -2875,11 +2875,8 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io) if (e) break; } READ_CHECK(fptr); - if (io_fillbuf(fptr) < 0) { - if (NIL_P(str)) return Qnil; - break; - } - } + } while (io_fillbuf(fptr) >= 0); + if (NIL_P(str)) return Qnil; str = io_enc_str(str, fptr); ENC_CODERANGE_SET(str, cr); @@ -3297,7 +3294,7 @@ rb_io_each_byte(VALUE io) RETURN_ENUMERATOR(io, 0, 0); GetOpenFile(io, fptr); - for (;;) { + do { while (fptr->rbuf.len > 0) { char *p = fptr->rbuf.ptr + fptr->rbuf.off++; fptr->rbuf.len--; @@ -3306,10 +3303,7 @@ rb_io_each_byte(VALUE io) } rb_io_check_byte_readable(fptr); READ_CHECK(fptr); - if (io_fillbuf(fptr) < 0) { - break; - } - } + } while (io_fillbuf(fptr) >= 0); return io; } @@ -3549,10 +3543,7 @@ rb_io_each_codepoint(VALUE io) } NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr); enc = io_input_encoding(fptr); - for (;;) { - if (io_fillbuf(fptr) < 0) { - return io; - } + while (io_fillbuf(fptr) >= 0) { r = rb_enc_precise_mbclen(fptr->rbuf.ptr+fptr->rbuf.off, fptr->rbuf.ptr+fptr->rbuf.off+fptr->rbuf.len, enc); if (MBCLEN_CHARFOUND_P(r) && |