summaryrefslogtreecommitdiffstats
path: root/generic/tclNamesp.c
diff options
context:
space:
mode:
authorMiguel Sofer <miguel.sofer@gmail.com>2002-02-28 20:11:08 (GMT)
committerMiguel Sofer <miguel.sofer@gmail.com>2002-02-28 20:11:08 (GMT)
commitabca3bbbb671d4175e9635c34a9ade4e53334b2e (patch)
treefa408bd631d1615bf2fb846db312f9e592010a12 /generic/tclNamesp.c
parent3b911b1e99e8f3e7b310b2c3c2453d66ee1d2885 (diff)
downloadtcl-abca3bbbb671d4175e9635c34a9ade4e53334b2e.zip
tcl-abca3bbbb671d4175e9635c34a9ade4e53334b2e.tar.gz
tcl-abca3bbbb671d4175e9635c34a9ade4e53334b2e.tar.bz2
generic/tclNamesp.c: optimisation of namespace lookups [Patch 458872]
Diffstat (limited to 'generic/tclNamesp.c')
-rw-r--r--generic/tclNamesp.c32
1 files changed, 26 insertions, 6 deletions
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;
}
/*