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

ruby-changes:3198

From: ko1@a...
Date: 25 Dec 2007 18:53:20 +0900
Subject: [ruby-changes:3198] matz - Ruby:r14691 (trunk): * io.c (appendline): move RS comparison to rb_io_getline_1().

matz	2007-12-25 18:52:52 +0900 (Tue, 25 Dec 2007)

  New Revision: 14691

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_io.rb
    trunk/bootstraptest/test_knownbug.rb
    trunk/io.c

  Log:
    * io.c (appendline): move RS comparison to rb_io_getline_1().

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_io.rb?r1=14691&r2=14690
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14691&r2=14690
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=14691&r2=14690
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14691&r2=14690

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14690)
+++ ChangeLog	(revision 14691)
@@ -4,6 +4,10 @@
 
 	 vm.c: comment out debug functions.
 
+Tue Dec 25 18:37:42 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* io.c (appendline): move RS comparison to rb_io_getline_1().
+
 Tue Dec 25 18:27:51 2007  Tanaka Akira  <akr@f...>
 
 	* string.c (rb_str_each_line): don't call rb_enc_codepoint with empty
Index: bootstraptest/test_knownbug.rb
===================================================================
--- bootstraptest/test_knownbug.rb	(revision 14690)
+++ bootstraptest/test_knownbug.rb	(revision 14691)
@@ -3,16 +3,6 @@
 # So all tests will cause failure.
 #
 
-assert_finish 1, %q{
-  r, w = IO.pipe
-  Thread.new {
-  w << "ab"
-  sleep 0.1
-  w << "ab"
-  }
-  p r.gets("abab")
-}
-
 assert_normal_exit %q{
   begin
     raise
Index: bootstraptest/test_io.rb
===================================================================
--- bootstraptest/test_io.rb	(revision 14690)
+++ bootstraptest/test_io.rb	(revision 14691)
@@ -26,3 +26,13 @@
   rescue LoadError
   end
 }, '[ruby-dev:32566]'
+
+assert_finish 1, %q{
+  r, w = IO.pipe
+  Thread.new {
+  w << "ab"
+  sleep 0.1
+  w << "ab"
+  }
+  p r.gets("abab")
+}
Index: io.c
===================================================================
--- io.c	(revision 14690)
+++ io.c	(revision 14691)
@@ -1665,12 +1665,11 @@
 }
 
 static int
-appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE rs, VALUE *strp, long *lp)
+appendline(rb_io_t *fptr, int delim, const char *rsptr, int rslen, VALUE *strp, long *lp)
 {
     VALUE str = *strp;
     int c = EOF;
     long limit = *lp;
-    rb_encoding *enc = io_input_encoding(fptr);
 
     if (rsptr == 0)
       rslen = 1;
@@ -1678,34 +1677,14 @@
     do {
 	long pending = READ_DATA_PENDING_COUNT(fptr);
 	if (pending > 0) {
-	    const char *s = READ_DATA_PENDING_PTR(fptr);
-	    const char *p, *e, *pp;
+	    const char *p = READ_DATA_PENDING_PTR(fptr);
+	    const char *e;
 	    long last = 0, len = (c != EOF);
 
 	    if (limit > 0 && pending > limit) pending = limit;
-	    pp = p = s;
 	  again:
 	    e = memchr(p, delim, pending);
-	    if (e) {
-		const char *p0 = e - rslen + 1;
-		if (p0 < s) {
-		    p = e + 1;
-		    goto again;
-		}
-		pp = rb_enc_left_char_head(pp, p0, enc);
-		if (pp != p0) {
-		    p = e + 1;
-		    goto again;
-		}
-		if (rsptr) {
-		    rscheck(rsptr, rslen, rs);
-		    if (memcmp(p0, rsptr, rslen) != 0) {
-			p = e + 1;
-			goto again;
-		    }
-		}
-		pending = e - s + 1;
-	    }
+	    if (e) pending = e - p + 1;
 	    len += pending;
 	    if (!NIL_P(str)) {
 		last = RSTRING_LEN(str);
@@ -1785,7 +1764,7 @@
     int c, nolimit = 0;
 
     for (;;) {
-	c = appendline(fptr, delim, 0, 0, 0, &str, &limit);
+	c = appendline(fptr, delim, 0, 0, &str, &limit);
 	if (c == EOF || c == delim) break;
 	if (limit == 0) {
 	    nolimit = 1;
@@ -1853,9 +1832,11 @@
     VALUE str = Qnil;
     rb_io_t *fptr;
     int nolimit = 0;
+    rb_encoding *enc;
 
     GetOpenFile(io, fptr);
     rb_io_check_readable(fptr);
+    enc = io_input_encoding(fptr);
     if (NIL_P(rs)) {
 	str = read_all(fptr, 0, Qnil);
 	if (RSTRING_LEN(str) == 0) return Qnil;
@@ -1888,9 +1869,17 @@
 	}
 	newline = rsptr[rslen - 1];
 
-	while ((c = appendline(fptr, newline, rsptr, rslen, rs, &str, &limit)) != EOF) {
+	while ((c = appendline(fptr, newline, rsptr, rslen, &str, &limit)) != EOF) {
 	    if (c == newline) {
-		break;
+		const char *s, *p, *pp;
+		
+		if (RSTRING_LEN(str) < rslen) continue;
+		s = RSTRING_PTR(str);
+		p = s +  RSTRING_LEN(str) - rslen;
+		pp = rb_enc_left_char_head(s, p, enc);
+		if (pp != p) continue;
+		if (!rspara) rscheck(rsptr, rslen, rs);
+		if (memcmp(p, rsptr, rslen) == 0) break;
 	    }
 	    if (limit == 0) {
 		nolimit = 1;

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

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