ruby-changes:43354
From: nobu <ko1@a...>
Date: Thu, 16 Jun 2016 12:18:01 +0900 (JST)
Subject: [ruby-changes:43354] nobu:r55428 (trunk): string.c: adjust buffer size
nobu 2016-06-16 12:17:54 +0900 (Thu, 16 Jun 2016) New Revision: 55428 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55428 Log: string.c: adjust buffer size * string.c (tr_trans): adjust buffer size by processed and rest lengths, instead of doubling repeatedly. Modified files: trunk/ChangeLog trunk/string.c Index: string.c =================================================================== --- string.c (revision 55427) +++ string.c (revision 55428) @@ -6342,9 +6342,8 @@ tr_trans(VALUE str, VALUE src, VALUE rep https://github.com/ruby/ruby/blob/trunk/string.c#L6342 c = c0; if (enc != e1) may_modify = 1; } - while (t - buf + tlen >= max) { - offset = t - buf; - max *= 2; + if ((offset = t - buf) + tlen > max) { + max = offset + tlen + (send - s); REALLOC_N(buf, char, max + termlen); t = buf + offset; } @@ -6415,9 +6414,8 @@ tr_trans(VALUE str, VALUE src, VALUE rep https://github.com/ruby/ruby/blob/trunk/string.c#L6414 c = c0; if (enc != e1) may_modify = 1; } - while (t - buf + tlen >= max) { - offset = t - buf; - max *= 2; + if ((offset = t - buf) + tlen > max) { + max = offset + tlen + (long)((send - s) * 1.2); REALLOC_N(buf, char, max + termlen); t = buf + offset; } Index: ChangeLog =================================================================== --- ChangeLog (revision 55427) +++ ChangeLog (revision 55428) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jun 16 12:17:52 2016 Nobuyoshi Nakada <nobu@r...> + + * string.c (tr_trans): adjust buffer size by processed and rest + lengths, instead of doubling repeatedly. + Thu Jun 16 11:15:25 2016 Nobuyoshi Nakada <nobu@r...> * string.c (tr_trans): consider terminator length and fix heap -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/