summaryrefslogtreecommitdiffstats
path: root/generic/tclCompile.c
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2008-07-22 21:41:48 (GMT)
committerandreas_kupries <akupries@shaw.ca>2008-07-22 21:41:48 (GMT)
commit9f031215bb9752fcfc9c9065039b509c0962117e (patch)
tree60a7f49c73794657a02d93ddc3f272200e6f0c2d /generic/tclCompile.c
parent63d4144a37db8c69be1a8090936516467f684480 (diff)
downloadtcl-9f031215bb9752fcfc9c9065039b509c0962117e.zip
tcl-9f031215bb9752fcfc9c9065039b509c0962117e.tar.gz
tcl-9f031215bb9752fcfc9c9065039b509c0962117e.tar.bz2
* generic/tclBasic.c: Reworked the handling of bytecode literals
* generic/tclCompile.c: for #280 to fix the abysmal performance * generic/tclCompile.h: for deep recursion, replaced the linear * generic/tclExecute.c: search through the whole stack with * generic/tclInt.h: another hashtable and simplified the data structure used by the compiler (array instead of hashtable). Incidentially this also fixes the memory leak reported via [Bug 2024937].
Diffstat (limited to 'generic/tclCompile.c')
-rw-r--r--generic/tclCompile.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c
index 88d8b86..79a9313 100644
--- a/generic/tclCompile.c
+++ b/generic/tclCompile.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCompile.c,v 1.150 2008/07/21 22:50:34 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclCompile.c,v 1.151 2008/07/22 21:41:51 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -801,8 +801,6 @@ TclCleanupByteCode(
if (hePtr) {
ExtCmdLoc *eclPtr = Tcl_GetHashValue(hePtr);
int i;
- Tcl_HashSearch hSearch;
- Tcl_HashEntry *hlPtr;
if (eclPtr->type == TCL_LOCATION_SOURCE) {
Tcl_DecrRefCount(eclPtr->path);
@@ -816,14 +814,10 @@ TclCleanupByteCode(
}
/* Release index of literals as well. */
- for (hlPtr = Tcl_FirstHashEntry(&eclPtr->litIndex, &hSearch);
- hlPtr != NULL;
- hlPtr = Tcl_NextHashEntry(&hSearch)) {
- ExtIndex* eiPtr = (ExtIndex*) Tcl_GetHashValue (hlPtr);
- ckfree((char*) eiPtr);
- Tcl_DeleteHashEntry (hlPtr);
+ if (eclPtr->eiloc != NULL) {
+ ckfree((char *) eclPtr->eiloc);
}
- Tcl_DeleteHashTable (&eclPtr->litIndex);
+
ckfree((char *) eclPtr);
Tcl_DeleteHashEntry(hePtr);
}
@@ -913,7 +907,9 @@ TclInitCompileEnv(
envPtr->extCmdMapPtr->nloc = 0;
envPtr->extCmdMapPtr->nuloc = 0;
envPtr->extCmdMapPtr->path = NULL;
- Tcl_InitHashTable(&envPtr->extCmdMapPtr->litIndex, TCL_ONE_WORD_KEYS);
+ envPtr->extCmdMapPtr->eiloc = NULL;
+ envPtr->extCmdMapPtr->neiloc = 0;
+ envPtr->extCmdMapPtr->nueiloc = 0;
if (invoker == NULL) {
/*
@@ -2476,15 +2472,30 @@ TclEnterCmdWordIndex (eclPtr, obj, pc, word)
int pc;
int word;
{
- int new;
- ExtIndex* eiPtr = (ExtIndex*) ckalloc (sizeof (ExtIndex));
+ ExtIndex* eiPtr;
+
+ if (eclPtr->nueiloc >= eclPtr->neiloc) {
+ /*
+ * Expand the ExtIndex array by allocating more storage from the heap. The
+ * currently allocated ECL entries are stored from eclPtr->loc[0] up
+ * to eclPtr->loc[eclPtr->nuloc-1] (inclusive).
+ */
+
+ size_t currElems = eclPtr->neiloc;
+ size_t newElems = (currElems ? 2*currElems : 1);
+ size_t newBytes = newElems * sizeof(ExtIndex);
+
+ eclPtr->eiloc = (ExtIndex *) ckrealloc((char *)(eclPtr->eiloc), newBytes);
+ eclPtr->neiloc = newElems;
+ }
+
+ eiPtr = &eclPtr->eiloc[eclPtr->nueiloc];
+ eiPtr->obj = obj;
eiPtr->pc = pc;
eiPtr->word = word;
- Tcl_SetHashValue (Tcl_CreateHashEntry (&eclPtr->litIndex,
- (char*) obj, &new),
- eiPtr);
+ eclPtr->nueiloc ++;
}
/*