From 9b15de84f1628712b63134c70392a770fa021068 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Thu, 6 Mar 2014 13:17:12 -0300 Subject: [PATCH] Grow message by just the needed amount Do not allocate more space than required for the message to grow. We used to nearly double the amount of space every time, which is nice to avoid quadratic complexity, but files are small enough that it probably doesn't matter much, and it just makes things confusing. --- decfile.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/decfile.c b/decfile.c index bfaf1ee..f300d69 100644 --- a/decfile.c +++ b/decfile.c @@ -430,13 +430,15 @@ static int append_stripped_reg_ctrl(struct rnet_message **message, char *line) { size_t len; struct rnet_message *msg = *message; + int growth; if (!decfile_reg_is_dec(line)) return 0; len = strlen(line); if (len < 12) return -EINVAL; - if (msg->alen - msg->len < len) { - if (rnet_message_expand(message, MAX(msg->len, len))) + growth = msg->len + len - 10 - msg->alen; + if (growth > 0) { + if (rnet_message_expand(message, growth)) return -ENOMEM; msg = *message; } -- 2.20.1