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

ruby-changes:29798

From: glass <ko1@a...>
Date: Tue, 9 Jul 2013 12:50:00 +0900 (JST)
Subject: [ruby-changes:29798] glass:r41850 (trunk): * io.c (appendline): use READ_CHAR_PENDING_XXX macros and

glass	2013-07-09 12:49:49 +0900 (Tue, 09 Jul 2013)

  New Revision: 41850

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

  Log:
    * io.c (appendline): use READ_CHAR_PENDING_XXX macros and
      RSTRING_END().
    
    * io.c (rb_io_getline_1): rewrite nested if statement into one
      statement.

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41849)
+++ ChangeLog	(revision 41850)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul  9 12:47:08 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* io.c (appendline): use READ_CHAR_PENDING_XXX macros and
+	  RSTRING_END().
+
+	* io.c (rb_io_getline_1): rewrite nested if statement into one
+	  statement.
+
 Tue Jul  9 11:04:35 2013  NAKAMURA Usaku  <usa@r...>
 
 	* ext/{dl,fiddle}/win32/lib/win32/registry.rb (Win32::Regstry#check):
Index: io.c
===================================================================
--- io.c	(revision 41849)
+++ io.c	(revision 41850)
@@ -2760,9 +2760,8 @@ appendline(rb_io_t *fptr, int delim, VAL https://github.com/ruby/ruby/blob/trunk/io.c#L2760
         do {
             const char *p, *e;
             int searchlen;
-            if (fptr->cbuf.len) {
-                p = fptr->cbuf.ptr+fptr->cbuf.off;
-                searchlen = fptr->cbuf.len;
+            if (searchlen = READ_CHAR_PENDING_COUNT(fptr)) {
+                p = READ_CHAR_PENDING_PTR(fptr);
                 if (0 < limit && limit < searchlen)
                     searchlen = (int)limit;
                 e = memchr(p, delim, searchlen);
@@ -3037,7 +3036,7 @@ rb_io_getline_1(VALUE rs, long limit, VA https://github.com/ruby/ruby/blob/trunk/io.c#L3036
 	    if (c == newline) {
 		if (RSTRING_LEN(str) < rslen) continue;
 		s = RSTRING_PTR(str);
-                e = s + RSTRING_LEN(str);
+                e = RSTRING_END(str);
 		p = e - rslen;
 		pp = rb_enc_left_char_head(s, p, e, enc);
 		if (pp != p) continue;
@@ -3046,7 +3045,7 @@ rb_io_getline_1(VALUE rs, long limit, VA https://github.com/ruby/ruby/blob/trunk/io.c#L3045
 	    }
 	    if (limit == 0) {
 		s = RSTRING_PTR(str);
-		p = s + RSTRING_LEN(str);
+		p = RSTRING_END(str);
 		pp = rb_enc_left_char_head(s, p-1, p, enc);
                 if (extra_limit &&
                     MBCLEN_NEEDMORE_P(rb_enc_precise_mbclen(pp, p, enc))) {
@@ -3062,25 +3061,20 @@ rb_io_getline_1(VALUE rs, long limit, VA https://github.com/ruby/ruby/blob/trunk/io.c#L3061
 	    }
 	}
 
-	if (rspara) {
-	    if (c != EOF) {
-		swallow(fptr, '\n');
-	    }
-	}
+	if (rspara && c != EOF)
+	    swallow(fptr, '\n');
 	if (!NIL_P(str))
             str = io_enc_str(str, fptr);
     }
 
-    if (!NIL_P(str)) {
-	if (!nolimit) {
-	    fptr->lineno++;
-	    if (io == ARGF.current_file) {
-		ARGF.lineno++;
-		ARGF.last_lineno = ARGF.lineno;
-	    }
-	    else {
-		ARGF.last_lineno = fptr->lineno;
-	    }
+    if (!NIL_P(str) && !nolimit) {
+	fptr->lineno++;
+	if (io == ARGF.current_file) {
+	    ARGF.lineno++;
+	    ARGF.last_lineno = ARGF.lineno;
+	}
+	else {
+	    ARGF.last_lineno = fptr->lineno;
 	}
     }
 

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

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