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
This commit is contained in:
parent
9f2e85a33c
commit
dfd0cbece0
21
io.c
21
io.c
@ -2849,7 +2849,7 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io)
|
|||||||
long pos = 0;
|
long pos = 0;
|
||||||
int cr = 0;
|
int cr = 0;
|
||||||
|
|
||||||
for (;;) {
|
do {
|
||||||
int pending = READ_DATA_PENDING_COUNT(fptr);
|
int pending = READ_DATA_PENDING_COUNT(fptr);
|
||||||
|
|
||||||
if (pending > 0) {
|
if (pending > 0) {
|
||||||
@ -2875,11 +2875,8 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc, VALUE io)
|
|||||||
if (e) break;
|
if (e) break;
|
||||||
}
|
}
|
||||||
READ_CHECK(fptr);
|
READ_CHECK(fptr);
|
||||||
if (io_fillbuf(fptr) < 0) {
|
} while (io_fillbuf(fptr) >= 0);
|
||||||
if (NIL_P(str)) return Qnil;
|
if (NIL_P(str)) return Qnil;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
str = io_enc_str(str, fptr);
|
str = io_enc_str(str, fptr);
|
||||||
ENC_CODERANGE_SET(str, cr);
|
ENC_CODERANGE_SET(str, cr);
|
||||||
@ -3297,7 +3294,7 @@ rb_io_each_byte(VALUE io)
|
|||||||
RETURN_ENUMERATOR(io, 0, 0);
|
RETURN_ENUMERATOR(io, 0, 0);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
|
|
||||||
for (;;) {
|
do {
|
||||||
while (fptr->rbuf.len > 0) {
|
while (fptr->rbuf.len > 0) {
|
||||||
char *p = fptr->rbuf.ptr + fptr->rbuf.off++;
|
char *p = fptr->rbuf.ptr + fptr->rbuf.off++;
|
||||||
fptr->rbuf.len--;
|
fptr->rbuf.len--;
|
||||||
@ -3306,10 +3303,7 @@ rb_io_each_byte(VALUE io)
|
|||||||
}
|
}
|
||||||
rb_io_check_byte_readable(fptr);
|
rb_io_check_byte_readable(fptr);
|
||||||
READ_CHECK(fptr);
|
READ_CHECK(fptr);
|
||||||
if (io_fillbuf(fptr) < 0) {
|
} while (io_fillbuf(fptr) >= 0);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return io;
|
return io;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3549,10 +3543,7 @@ rb_io_each_codepoint(VALUE io)
|
|||||||
}
|
}
|
||||||
NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr);
|
NEED_NEWLINE_DECORATOR_ON_READ_CHECK(fptr);
|
||||||
enc = io_input_encoding(fptr);
|
enc = io_input_encoding(fptr);
|
||||||
for (;;) {
|
while (io_fillbuf(fptr) >= 0) {
|
||||||
if (io_fillbuf(fptr) < 0) {
|
|
||||||
return io;
|
|
||||||
}
|
|
||||||
r = rb_enc_precise_mbclen(fptr->rbuf.ptr+fptr->rbuf.off,
|
r = rb_enc_precise_mbclen(fptr->rbuf.ptr+fptr->rbuf.off,
|
||||||
fptr->rbuf.ptr+fptr->rbuf.off+fptr->rbuf.len, enc);
|
fptr->rbuf.ptr+fptr->rbuf.off+fptr->rbuf.len, enc);
|
||||||
if (MBCLEN_CHARFOUND_P(r) &&
|
if (MBCLEN_CHARFOUND_P(r) &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user