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

ruby-changes:30061

From: glass <ko1@a...>
Date: Mon, 22 Jul 2013 18:42:27 +0900 (JST)
Subject: [ruby-changes:30061] glass:r42113 (trunk): * string.c (rb_str_enumerate_chars): specify array capa

glass	2013-07-22 18:42:15 +0900 (Mon, 22 Jul 2013)

  New Revision: 42113

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

  Log:
    * string.c (rb_str_enumerate_chars): specify array capa
      with str_strlen().
    
    * string.c (rb_str_enumerate_codepoints): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42112)
+++ ChangeLog	(revision 42113)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 22 18:39:52 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* string.c (rb_str_enumerate_chars): specify array capa
+	  with str_strlen().
+
+	* string.c (rb_str_enumerate_codepoints): ditto.
+
 Mon Jul 22 18:01:33 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* string.c (rb_str_enumerate_chars): specify array capa.
Index: string.c
===================================================================
--- string.c	(revision 42112)
+++ string.c	(revision 42113)
@@ -6514,11 +6514,16 @@ rb_str_enumerate_chars(VALUE str, int wa https://github.com/ruby/ruby/blob/trunk/string.c#L6514
     rb_encoding *enc;
     VALUE UNINITIALIZED_VAR(ary);
 
+    str = rb_str_new4(str);
+    ptr = RSTRING_PTR(str);
+    len = RSTRING_LEN(str);
+    enc = rb_enc_get(str);
+
     if (rb_block_given_p()) {
 	if (wantarray) {
 #if STRING_ENUMERATORS_WANTARRAY
 	    rb_warn("given block not used");
-	    ary = rb_ary_new_capa(rb_str_strlen(str));
+	    ary = rb_ary_new_capa(str_strlen(str, enc));
 #else
 	    rb_warning("passing a block to String#chars is deprecated");
 	    wantarray = 0;
@@ -6527,15 +6532,11 @@ rb_str_enumerate_chars(VALUE str, int wa https://github.com/ruby/ruby/blob/trunk/string.c#L6532
     }
     else {
 	if (wantarray)
-	    ary = rb_ary_new_capa(rb_str_strlen(str));
+	    ary = rb_ary_new_capa(str_strlen(str, enc));
 	else
 	    RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
     }
 
-    str = rb_str_new4(str);
-    ptr = RSTRING_PTR(str);
-    len = RSTRING_LEN(str);
-    enc = rb_enc_get(str);
     switch (ENC_CODERANGE(str)) {
       case ENC_CODERANGE_VALID:
       case ENC_CODERANGE_7BIT:
@@ -6617,11 +6618,16 @@ rb_str_enumerate_codepoints(VALUE str, i https://github.com/ruby/ruby/blob/trunk/string.c#L6618
     if (single_byte_optimizable(str))
 	return rb_str_enumerate_bytes(str, wantarray);
 
+    str = rb_str_new4(str);
+    ptr = RSTRING_PTR(str);
+    end = RSTRING_END(str);
+    enc = STR_ENC_GET(str);
+
     if (rb_block_given_p()) {
 	if (wantarray) {
 #if STRING_ENUMERATORS_WANTARRAY
 	    rb_warn("given block not used");
-	    ary = rb_ary_new();
+	    ary = rb_ary_new_capa(str_strlen(str, enc));
 #else
 	    rb_warning("passing a block to String#codepoints is deprecated");
 	    wantarray = 0;
@@ -6630,15 +6636,11 @@ rb_str_enumerate_codepoints(VALUE str, i https://github.com/ruby/ruby/blob/trunk/string.c#L6636
     }
     else {
 	if (wantarray)
-	    ary = rb_ary_new();
+	    ary = rb_ary_new_capa(str_strlen(str, enc));
 	else
 	    RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
     }
 
-    str = rb_str_new4(str);
-    ptr = RSTRING_PTR(str);
-    end = RSTRING_END(str);
-    enc = STR_ENC_GET(str);
     while (ptr < end) {
 	c = rb_enc_codepoint_len(ptr, end, &n, enc);
 	if (wantarray)

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

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