aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-16 03:17:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-16 03:17:54 +0000
commit18fba42d8b17e08e95b89dfc5de0daa11417194f (patch)
tree9b29afb3f536df5abc2a9efa4edc07bf7a093e35 /string.c
parent9ac3d3b2a29ebbc111bbf47864fe613df1c01ed3 (diff)
downloadruby-18fba42d8b17e08e95b89dfc5de0daa11417194f.tar.gz
string.c: adjust buffer size
* string.c (tr_trans): adjust buffer size by processed and rest lengths, instead of doubling repeatedly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55428 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/string.c b/string.c
index 7cb6af2727..73e742696a 100644
--- a/string.c
+++ b/string.c
@@ -6342,9 +6342,8 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
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 repl, int sflag)
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;
}