diff options
author | dcs <dcs@FreeBSD.org> | 2000-05-05 02:06:38 +0000 |
---|---|---|
committer | dcs <dcs@FreeBSD.org> | 2000-05-05 02:06:38 +0000 |
commit | 64e1aa5faa0b6dbd7c0af5ae66aa3786d7d9d73e (patch) | |
tree | 3c2802f3a4cbe5a4ea1ddff0d2733f8ef424f0af | |
parent | 56f09cbe0e4f66622080af18eb162b2c3c6e5957 (diff) | |
download | FreeBSD-src-64e1aa5faa0b6dbd7c0af5ae66aa3786d7d9d73e.zip FreeBSD-src-64e1aa5faa0b6dbd7c0af5ae66aa3786d7d9d73e.tar.gz |
Lay the groundwork for on-demand dictionary expansion.
-rw-r--r-- | sys/boot/ficl/dict.c | 28 | ||||
-rw-r--r-- | sys/boot/ficl/ficl.h | 8 | ||||
-rw-r--r-- | sys/boot/ficl/words.c | 17 |
3 files changed, 48 insertions, 5 deletions
diff --git a/sys/boot/ficl/dict.c b/sys/boot/ficl/dict.c index 5b19dbc..a2f5990 100644 --- a/sys/boot/ficl/dict.c +++ b/sys/boot/ficl/dict.c @@ -29,6 +29,11 @@ #include <string.h> #include "ficl.h" +/* Dictionary on-demand resizing control variables */ +unsigned int dictThreshold; +unsigned int dictIncrease; + + static char *dictCopyName(FICL_DICT *pDict, STRINGINFO si); /************************************************************************** @@ -347,12 +352,14 @@ FICL_DICT *dictCreateHashed(unsigned nCells, unsigned nHash) FICL_DICT *pDict; size_t nAlloc; - nAlloc = sizeof (FICL_DICT) + nCells * sizeof (CELL) - + sizeof (FICL_HASH) + (nHash - 1) * sizeof (FICL_WORD *); + nAlloc = sizeof (FICL_HASH) + nCells * sizeof (CELL) + + (nHash - 1) * sizeof (FICL_WORD *); - pDict = ficlMalloc(nAlloc); + pDict = ficlMalloc(sizeof (FICL_DICT)); assert(pDict); memset(pDict, 0, sizeof (FICL_DICT)); + pDict->dict = ficlMalloc(nAlloc); + assert(pDict->dict); pDict->size = nCells; dictEmpty(pDict, nHash); return pDict; @@ -701,4 +708,19 @@ void hashReset(FICL_HASH *pHash) return; } +/************************************************************************** + d i c t C h e c k T h r e s h o l d +** Verify if an increase in the dictionary size is warranted, and do it if +** so. +**************************************************************************/ + +void dictCheckThreshold(FICL_DICT* dp) +{ + if( dictCellsAvail(dp) < dictThreshold ) { + dp->dict = ficlMalloc( dictIncrease * sizeof (CELL) ); + assert(dp->dict); + dp->here = dp->dict; + dp->size = dictIncrease; + } +} diff --git a/sys/boot/ficl/ficl.h b/sys/boot/ficl/ficl.h index 0bf1775..ac5e57e 100644 --- a/sys/boot/ficl/ficl.h +++ b/sys/boot/ficl/ficl.h @@ -666,7 +666,7 @@ typedef struct ficl_dict FICL_HASH *pSearch[FICL_DEFAULT_VOCS]; int nLists; unsigned size; /* Number of cells in dict (total)*/ - CELL dict[1]; /* Base of dictionary memory */ + CELL *dict; /* Base of dictionary memory */ } FICL_DICT; void *alignPtr(void *ptr); @@ -829,6 +829,12 @@ void constantParen(FICL_VM *pVM); void twoConstParen(FICL_VM *pVM); /* +** Dictionary on-demand resizing +*/ +extern unsigned int dictThreshold; +extern unsigned int dictIncrease; + +/* ** So we can more easily debug... */ #ifdef FICL_TRACE diff --git a/sys/boot/ficl/words.c b/sys/boot/ficl/words.c index 5baf6fb..179157c 100644 --- a/sys/boot/ficl/words.c +++ b/sys/boot/ficl/words.c @@ -72,7 +72,6 @@ static FICL_WORD *pUnLinkParen = NULL; static int nLocals = 0; #endif - /* ** C O N T R O L S T R U C T U R E B U I L D E R S ** @@ -431,6 +430,8 @@ static void colon(FICL_VM *pVM) FICL_DICT *dp = ficlGetDict(); STRINGINFO si = vmGetWord(pVM); + dictCheckThreshold(dp); + pVM->state = COMPILE; markControlTag(pVM, colonTag); dictAppendWord2(dp, si, colonParen, FW_DEFAULT | FW_SMUDGE); @@ -4472,6 +4473,18 @@ static void dnegate(FICL_VM *pVM) return; } +/******************* Increase dictionary size on-demand ******************/ + +static void ficlDictThreshold(FICL_VM *pVM) +{ + stackPushPtr(pVM->pStack, &dictThreshold); +} + +static void ficlDictIncrease(FICL_VM *pVM) +{ + stackPushPtr(pVM->pStack, &dictIncrease); +} + /************************* freebsd added trace ***************************/ #ifdef FICL_TRACE @@ -4658,6 +4671,8 @@ void ficlCompileCore(FICL_DICT *dp) dictAppendWord(dp, "ms", ms, FW_DEFAULT); dictAppendWord(dp, "seconds", pseconds, FW_DEFAULT); dictAppendWord(dp, "heap?", freeHeap, FW_DEFAULT); + dictAppendWord(dp, "dictthreshold", ficlDictThreshold, FW_DEFAULT); + dictAppendWord(dp, "dictincrease", ficlDictIncrease, FW_DEFAULT); #ifdef FICL_TRACE dictAppendWord(dp, "trace!", ficlTrace, FW_DEFAULT); #endif |