aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauri Kasanen <cand@gmx.com>2013-03-14 20:28:37 +0200
committerSteve Bennett <steveb@workware.net.au>2013-03-26 22:44:25 +1000
commitd2dc691ed373832aa7b3c93971439a9762543db2 (patch)
tree6c11925c60b32703f8936e182a1c83cd6201c0f4
parent81d35bbd0429a499c21b4ba78b44f2cea7946b4f (diff)
downloadjimtcl-d2dc691ed373832aa7b3c93971439a9762543db2.zip
jimtcl-d2dc691ed373832aa7b3c93971439a9762543db2.tar.gz
jimtcl-d2dc691ed373832aa7b3c93971439a9762543db2.tar.bz2
Avoid list allocations under four pointers (16/32 bytes)
It's more overhead than usable space to get space for two pointers. Signed-off-by: Lauri Kasanen <cand@gmx.com>
-rw-r--r--jim.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/jim.c b/jim.c
index dd96178..e984093 100644
--- a/jim.c
+++ b/jim.c
@@ -6444,10 +6444,18 @@ static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *co
Jim_Obj **point;
if (requiredLen > listPtr->internalRep.listValue.maxLen) {
- listPtr->internalRep.listValue.maxLen = requiredLen * 2;
+ if (requiredLen < 2) {
+ /* Don't do allocations of under 4 pointers. */
+ requiredLen = 4;
+ }
+ else {
+ requiredLen *= 2;
+ }
listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
- sizeof(Jim_Obj *) * listPtr->internalRep.listValue.maxLen);
+ sizeof(Jim_Obj *) * requiredLen);
+
+ listPtr->internalRep.listValue.maxLen = requiredLen;
}
if (idx < 0) {
idx = currentLen;