diff options
author | andreas_kupries <akupries@shaw.ca> | 2008-07-22 21:41:10 (GMT) |
---|---|---|
committer | andreas_kupries <akupries@shaw.ca> | 2008-07-22 21:41:10 (GMT) |
commit | 29341bbc6ca4be934e01b591b98bc01f0a93f57b (patch) | |
tree | 75818190d610cf0a24cef9ff5ccfa0384c131e8c /generic/tclCompile.c | |
parent | af7d3aa263b52ca80b11922cf1af375a3b683d0e (diff) | |
download | tcl-29341bbc6ca4be934e01b591b98bc01f0a93f57b.zip tcl-29341bbc6ca4be934e01b591b98bc01f0a93f57b.tar.gz tcl-29341bbc6ca4be934e01b591b98bc01f0a93f57b.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.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c index 145a7b9..19011d9 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.146.2.2 2008/07/21 19:38:17 andreas_kupries Exp $ + * RCS: @(#) $Id: tclCompile.c,v 1.146.2.3 2008/07/22 21:41:12 andreas_kupries Exp $ */ #include "tclInt.h" @@ -802,8 +802,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); @@ -817,14 +815,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); } @@ -914,7 +908,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) { /* @@ -2446,15 +2442,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 ++; } /* |