aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--string.c10
2 files changed, 9 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 869fd9535e..3b264b63e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jun 16 12:17:52 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* string.c (tr_trans): consider terminator length and fix heap
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;
}