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

ruby-changes:34332

From: nobu <ko1@a...>
Date: Thu, 12 Jun 2014 20:33:16 +0900 (JST)
Subject: [ruby-changes:34332] nobu:r46413 (trunk): string.c: consider capacity

nobu	2014-06-12 20:33:12 +0900 (Thu, 12 Jun 2014)

  New Revision: 46413

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

  Log:
    string.c: consider capacity
    
    * string.c (rb_str_resize): should consider the capacity instead
      of the old length, as pointed out by nagachika.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46412)
+++ ChangeLog	(revision 46413)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun 12 20:32:28 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_resize): should consider the capacity instead
+	  of the old length, as pointed out by nagachika.
+
 Thu Jun 12 18:31:01 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* lib/net/http/responses.rb: added Net::HTTPPermanentRedirect(308)
Index: string.c
===================================================================
--- string.c	(revision 46412)
+++ string.c	(revision 46413)
@@ -1996,7 +1996,7 @@ rb_str_resize(VALUE str, long len) https://github.com/ruby/ruby/blob/trunk/string.c#L1996
 	    if (len == slen) return str;
 	    str_make_independent_expand(str, len - slen);
 	}
-	else if (slen < len || slen - len > 1024) {
+	else if (slen < len || (RSTRING(str)->as.heap.aux.capa - len) > (len < 1024 ? len : 1024)) {
 	    REALLOC_N(RSTRING(str)->as.heap.ptr, char, len + termlen);
 	}
 	else if (len == slen) return str;

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

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