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

ruby-changes:26565

From: nobu <ko1@a...>
Date: Wed, 26 Dec 2012 07:31:33 +0900 (JST)
Subject: [ruby-changes:26565] nobu:r38616 (trunk): string.c: reduce duplicated code

nobu	2012-12-26 07:31:21 +0900 (Wed, 26 Dec 2012)

  New Revision: 38616

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

  Log:
    string.c: reduce duplicated code
    
    * string.c (rb_str_enumerate_lines, rb_str_chop): reduce duplicated
      code.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38615)
+++ ChangeLog	(revision 38616)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Dec 26 07:31:14 2012  Nobuyoshi Nakada  <nobu@r...>
+Wed Dec 26 07:31:19 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_enumerate_lines, rb_str_chop): reduce duplicated
+	  code.
 
 	* string.c (rb_str_enumerate_chars): prevent shared copy from GC.
 
Index: string.c
===================================================================
--- string.c	(revision 38615)
+++ string.c	(revision 38616)
@@ -6161,9 +6161,7 @@ rb_str_enumerate_lines(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L6161
 		continue;
 	    }
 	    p = p0 + rb_enc_mbclen(p0, pend, enc);
-	    line = rb_str_new5(str, s, p - s);
-	    OBJ_INFECT(line, str);
-	    rb_enc_cr_str_copy_for_substr(line, str);
+	    line = rb_str_subseq(str, s - ptr, p - s);
 	    if (wantarray)
 		rb_ary_push(ary, line);
 	    else
@@ -6200,24 +6198,21 @@ rb_str_enumerate_lines(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L6198
 	if (c == newline &&
 	    (rslen <= 1 ||
 	     (pend - p >= rslen && memcmp(RSTRING_PTR(rs), p, rslen) == 0))) {
-	    line = rb_str_new5(str, s, p - s + (rslen ? rslen : n));
-	    OBJ_INFECT(line, str);
-	    rb_enc_cr_str_copy_for_substr(line, str);
+	    p += (rslen ? rslen : n);
+	    line = rb_str_subseq(str, s - ptr, p - s);
 	    if (wantarray)
 		rb_ary_push(ary, line);
 	    else
 		rb_yield(line);
 	    str_mod_check(str, ptr, len);
-	    s = p + (rslen ? rslen : n);
+	    s = p;
 	}
 	p += n;
     }
 
   finish:
     if (s != pend) {
-	line = rb_str_new5(str, s, pend - s);
-	OBJ_INFECT(line, str);
-	rb_enc_cr_str_copy_for_substr(line, str);
+	line = rb_str_subseq(str, s - ptr, pend - s);
 	if (wantarray)
 	    rb_ary_push(ary, line);
 	else
@@ -6643,10 +6638,7 @@ rb_str_chop_bang(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L6638
 static VALUE
 rb_str_chop(VALUE str)
 {
-    VALUE str2 = rb_str_new5(str, RSTRING_PTR(str), chopped_length(str));
-    rb_enc_cr_str_copy_for_substr(str2, str);
-    OBJ_INFECT(str2, str);
-    return str2;
+    return rb_str_subseq(str, 0, chopped_length(str));
 }
 
 

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

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