[前][次][番号順一覧][スレッド一覧]

ruby-changes:27167

From: nobu <ko1@a...>
Date: Wed, 13 Feb 2013 17:51:34 +0900 (JST)
Subject: [ruby-changes:27167] nobu:r39219 (trunk): io.c: simplify

nobu	2013-02-13 17:51:25 +0900 (Wed, 13 Feb 2013)

  New Revision: 39219

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39219

  Log:
    io.c: simplify
    
    * io.c (rb_io_getline_fast, rb_io_each_{byte,codepoint}): simplify
      loops.

  Modified files:
    trunk/io.c

Index: io.c
===================================================================
--- io.c	(revision 39218)
+++ io.c	(revision 39219)
@@ -2849,7 +2849,7 @@ rb_io_getline_fast(rb_io_t *fptr, rb_enc https://github.com/ruby/ruby/blob/trunk/io.c#L2849
     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_enc https://github.com/ruby/ruby/blob/trunk/io.c#L2875
 	    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) https://github.com/ruby/ruby/blob/trunk/io.c#L3294
     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) https://github.com/ruby/ruby/blob/trunk/io.c#L3303
 	}
 	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) https://github.com/ruby/ruby/blob/trunk/io.c#L3543
     }
     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) &&

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]