diff options
author | Lauri Kasanen <cand@gmx.com> | 2013-03-14 20:28:37 +0200 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2013-03-26 22:44:25 +1000 |
commit | d2dc691ed373832aa7b3c93971439a9762543db2 (patch) | |
tree | 6c11925c60b32703f8936e182a1c83cd6201c0f4 | |
parent | 81d35bbd0429a499c21b4ba78b44f2cea7946b4f (diff) | |
download | jimtcl-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.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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; |