diff options
author | dgp <dgp@users.sourceforge.net> | 2017-12-05 15:12:05 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2017-12-05 15:12:05 (GMT) |
commit | 3eef9fcea1274b68161aa2c5ebfb6a975ac7143a (patch) | |
tree | 4f7fc0d500ce67e54f6e0126dda854b828b8f894 /generic/tclNamesp.c | |
parent | 906cf353b260757994a8c6fcf1f7dc34df32958a (diff) | |
download | tcl-3eef9fcea1274b68161aa2c5ebfb6a975ac7143a.zip tcl-3eef9fcea1274b68161aa2c5ebfb6a975ac7143a.tar.gz tcl-3eef9fcea1274b68161aa2c5ebfb6a975ac7143a.tar.bz2 |
Factor clearing of ensemble subcommand table into utility routine.
Diffstat (limited to 'generic/tclNamesp.c')
-rw-r--r-- | generic/tclNamesp.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index 1556ec9..a2e625e 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -6480,13 +6480,31 @@ MakeCachedEnsembleCommand( */ static void +ClearTable( + EnsembleConfig *ensemblePtr) +{ + Tcl_HashTable *hash = &ensemblePtr->subcommandTable; + + if (hash->numEntries != 0) { + Tcl_HashSearch search; + Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(hash, &search); + + while (hPtr != NULL) { + Tcl_Obj *prefixObj = Tcl_GetHashValue(hPtr); + Tcl_DecrRefCount(prefixObj); + hPtr = Tcl_NextHashEntry(&search); + } + ckfree((char *) ensemblePtr->subcommandArrayPtr); + } + Tcl_DeleteHashTable(hash); +} + +static void DeleteEnsembleConfig( ClientData clientData) { EnsembleConfig *ensemblePtr = clientData; Namespace *nsPtr = ensemblePtr->nsPtr; - Tcl_HashSearch search; - Tcl_HashEntry *hEnt; /* * Unlink from the ensemble chain if it has not been marked as having been @@ -6519,17 +6537,8 @@ DeleteEnsembleConfig( * Kill the pointer-containing fields. */ - if (ensemblePtr->subcommandTable.numEntries != 0) { - ckfree((char *) ensemblePtr->subcommandArrayPtr); - } - hEnt = Tcl_FirstHashEntry(&ensemblePtr->subcommandTable, &search); - while (hEnt != NULL) { - Tcl_Obj *prefixObj = Tcl_GetHashValue(hEnt); + ClearTable(ensemblePtr); - Tcl_DecrRefCount(prefixObj); - hEnt = Tcl_NextHashEntry(&search); - } - Tcl_DeleteHashTable(&ensemblePtr->subcommandTable); if (ensemblePtr->subcmdList != NULL) { Tcl_DecrRefCount(ensemblePtr->subcmdList); } @@ -6585,23 +6594,8 @@ BuildEnsembleConfig( Tcl_Obj *mapDict = ensemblePtr->subcommandDict; Tcl_Obj *subList = ensemblePtr->subcmdList; - if (hash->numEntries != 0) { - /* - * Remove pre-existing table. - */ - - Tcl_HashSearch search; - - ckfree((char *) ensemblePtr->subcommandArrayPtr); - hPtr = Tcl_FirstHashEntry(hash, &search); - while (hPtr != NULL) { - Tcl_Obj *prefixObj = Tcl_GetHashValue(hPtr); - Tcl_DecrRefCount(prefixObj); - hPtr = Tcl_NextHashEntry(&search); - } - Tcl_DeleteHashTable(hash); - Tcl_InitHashTable(hash, TCL_STRING_KEYS); - } + ClearTable(ensemblePtr); + Tcl_InitHashTable(hash, TCL_STRING_KEYS); if (subList) { int subc; |