From abca3bbbb671d4175e9635c34a9ade4e53334b2e Mon Sep 17 00:00:00 2001 From: Miguel Sofer Date: Thu, 28 Feb 2002 20:11:08 +0000 Subject: generic/tclNamesp.c: optimisation of namespace lookups [Patch 458872] --- ChangeLog | 6 ++++++ generic/tclNamesp.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7505cd2..3dd1440 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2002-02-28 Miguel Sofer + * generic/tclNamesp.c: allow cached fully-qualified namespace + names to be usable from different namespaces within the same + interpreter without forcing a new lookup [Patch 458872]. + +2002-02-28 Miguel Sofer + * generic/tclExecute.c: Replaced a few direct stack accesses with the POP_OBJECT() macro [Bug 507181] (Don Porter). diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index 3e4d889..da0df83 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -19,7 +19,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclNamesp.c,v 1.28 2002/01/25 22:01:32 dgp Exp $ + * RCS: @(#) $Id: tclNamesp.c,v 1.29 2002/02/28 20:11:09 msofer Exp $ */ #include "tclInt.h" @@ -2364,12 +2364,29 @@ GetNamespaceFromObj(interp, objPtr, nsPtrPtr) * of a namespace. */ Tcl_Namespace **nsPtrPtr; /* Result namespace pointer goes here. */ { + Interp *iPtr = (Interp *) interp; register ResolvedNsName *resNamePtr; register Namespace *nsPtr; - Namespace *currNsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp); - int result; + Namespace *currNsPtr; + CallFrame *savedFramePtr; + int result = TCL_OK; + char *name; /* + * If the namespace name is fully qualified, do as if the lookup were + * done from the global namespace; this helps avoid repeated lookups + * of fully qualified names. + */ + + savedFramePtr = iPtr->varFramePtr; + name = Tcl_GetString(objPtr); + if ((*name++ == ':') && (*name == ':')) { + iPtr->varFramePtr = NULL; + } + + currNsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp); + + /* * Get the internal representation, converting to a namespace type if * needed. The internal representation is a ResolvedNsName that points * to the actual namespace. @@ -2378,7 +2395,7 @@ GetNamespaceFromObj(interp, objPtr, nsPtrPtr) if (objPtr->typePtr != &tclNsNameType) { result = tclNsNameType.setFromAnyProc(interp, objPtr); if (result != TCL_OK) { - return TCL_ERROR; + goto done; } } resNamePtr = (ResolvedNsName *) objPtr->internalRep.otherValuePtr; @@ -2404,7 +2421,7 @@ GetNamespaceFromObj(interp, objPtr, nsPtrPtr) if (nsPtr == NULL) { /* try again */ result = tclNsNameType.setFromAnyProc(interp, objPtr); if (result != TCL_OK) { - return TCL_ERROR; + goto done; } resNamePtr = (ResolvedNsName *) objPtr->internalRep.otherValuePtr; if (resNamePtr != NULL) { @@ -2415,7 +2432,10 @@ GetNamespaceFromObj(interp, objPtr, nsPtrPtr) } } *nsPtrPtr = (Tcl_Namespace *) nsPtr; - return TCL_OK; + + done: + iPtr->varFramePtr = savedFramePtr; + return result; } /* -- cgit v0.12