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

ruby-changes:34343

From: nobu <ko1@a...>
Date: Sat, 14 Jun 2014 10:53:38 +0900 (JST)
Subject: [ruby-changes:34343] nobu:r46424 (trunk): string.c: fix wrong capa

nobu	2014-06-14 10:53:32 +0900 (Sat, 14 Jun 2014)

  New Revision: 46424

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

  Log:
    string.c: fix wrong capa
    
    * string.c (rb_str_resize): update capa only when buffer get
      reallocated.
      http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46423)
+++ ChangeLog	(revision 46424)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 14 10:52:15 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_resize): update capa only when buffer get
+	  reallocated.
+	  http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413
+
 Sat Jun 14 08:28:59 2014  Zachary Scott  <e@z...>
 
 	* man/rake.1: [DOC] Update links for Rake, patch by @hsbt [Bug #9904]
Index: string.c
===================================================================
--- string.c	(revision 46423)
+++ string.c	(revision 46424)
@@ -1972,6 +1972,7 @@ rb_str_resize(VALUE str, long len) https://github.com/ruby/ruby/blob/trunk/string.c#L1972
     slen = RSTRING_LEN(str);
 
     {
+	long capa;
 	const int termlen = TERM_LEN(str);
 	if (STR_EMBED_P(str)) {
 	    if (len == slen) return str;
@@ -1996,11 +1997,12 @@ rb_str_resize(VALUE str, long len) https://github.com/ruby/ruby/blob/trunk/string.c#L1997
 	    if (len == slen) return str;
 	    str_make_independent_expand(str, len - slen);
 	}
-	else if (slen < len || (RSTRING(str)->as.heap.aux.capa - len) > (len < 1024 ? len : 1024)) {
+	else if ((capa = RSTRING(str)->as.heap.aux.capa) < len ||
+		 (capa - len) > (len < 1024 ? len : 1024)) {
 	    REALLOC_N(RSTRING(str)->as.heap.ptr, char, len + termlen);
+	    RSTRING(str)->as.heap.aux.capa = len;
 	}
 	else if (len == slen) return str;
-	RSTRING(str)->as.heap.aux.capa = len;
 	RSTRING(str)->as.heap.len = len;
 	TERM_FILL(RSTRING(str)->as.heap.ptr + len, termlen); /* sentinel */
     }

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

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