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

ruby-changes:34327

From: nobu <ko1@a...>
Date: Thu, 12 Jun 2014 13:09:47 +0900 (JST)
Subject: [ruby-changes:34327] nobu:r46408 (trunk): string.c: shrink too big buffer

nobu	2014-06-12 13:09:26 +0900 (Thu, 12 Jun 2014)

  New Revision: 46408

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

  Log:
    string.c: shrink too big buffer
    
    * string.c (rb_str_resize): shrink the buffer even if new length
      is same but it is enough smaller than the capacity.

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 46407)
+++ string.c	(revision 46408)
@@ -1969,9 +1969,10 @@ rb_str_resize(VALUE str, long len) https://github.com/ruby/ruby/blob/trunk/string.c#L1969
     ENC_CODERANGE_CLEAR(str);
     slen = RSTRING_LEN(str);
 
-    if (len != slen) {
+    {
 	const int termlen = TERM_LEN(str);
 	if (STR_EMBED_P(str)) {
+	    if (len == slen) return str;
 	    if (len + termlen <= RSTRING_EMBED_LEN_MAX + 1) {
 		STR_SET_EMBED_LEN(str, len);
 		TERM_FILL(RSTRING(str)->as.ary + len, termlen);
@@ -1990,11 +1991,13 @@ rb_str_resize(VALUE str, long len) https://github.com/ruby/ruby/blob/trunk/string.c#L1991
 	    return str;
 	}
 	else if (!independent) {
+	    if (len == slen) return str;
 	    str_make_independent_expand(str, len - slen);
 	}
 	else if (slen < len || slen - len > 1024) {
 	    REALLOC_N(RSTRING(str)->as.heap.ptr, char, len + termlen);
 	}
+	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/

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