diff --git a/ChangeLog b/ChangeLog index f94e8c2b45..429fa3bdf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Jun 14 10:52:15 2014 Nobuyoshi Nakada + + * 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 * man/rake.1: [DOC] Update links for Rake, patch by @hsbt [Bug #9904] diff --git a/string.c b/string.c index faf12f23e8..a8fd16ece3 100644 --- a/string.c +++ b/string.c @@ -1972,6 +1972,7 @@ rb_str_resize(VALUE str, long len) 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) 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 */ }