--- orig\tclNamesp.c	2005-10-28 12:24:40.515898100 +0100
+++ tclNamesp.c	2005-11-09 16:28:25.781575800 +0000
@@ -767,7 +767,9 @@
     CONST char *simpleName;
     Tcl_HashEntry *entryPtr;
     Tcl_DString buffer1, buffer2;
+    Tcl_DString *name_dstrp, *buff_dstrp, *temp_dstrp;
     int newEntry;
+    int name_len;
     ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
 
     /*
@@ -874,21 +876,26 @@
 
     Tcl_DStringInit(&buffer1);
     Tcl_DStringInit(&buffer2);
+    name_dstrp = &buffer1;
+    buff_dstrp = &buffer2;
     for (ancestorPtr = nsPtr;  ancestorPtr != NULL;
 	    ancestorPtr = ancestorPtr->parentPtr) {
 	if (ancestorPtr != globalNsPtr) {
-	    Tcl_DStringAppend(&buffer1, "::", 2);
-	    Tcl_DStringAppend(&buffer1, ancestorPtr->name, -1);
+	    Tcl_DStringAppend(buff_dstrp, "::", 2);
+	    Tcl_DStringAppend(buff_dstrp, ancestorPtr->name, -1);
+	    Tcl_DStringAppend(buff_dstrp, Tcl_DStringValue(name_dstrp),
+		    Tcl_DStringLength(name_dstrp));
+	    /* Now swap the buffer pointers */
+	    temp_dstrp = name_dstrp;
+	    name_dstrp = buff_dstrp;
+	    buff_dstrp = temp_dstrp;
+	    Tcl_DStringSetLength(buff_dstrp, 0);
 	}
-	Tcl_DStringAppend(&buffer1, Tcl_DStringValue(&buffer2), -1);
-
-	Tcl_DStringSetLength(&buffer2, 0);
-	Tcl_DStringAppend(&buffer2, Tcl_DStringValue(&buffer1), -1);
-	Tcl_DStringSetLength(&buffer1, 0);
     }
 
-    name = Tcl_DStringValue(&buffer2);
-    nsPtr->fullName = (char *) ckalloc((unsigned) (strlen(name)+1));
+    name = Tcl_DStringValue(name_dstrp);
+    name_len = Tcl_DStringLength(name_dstrp);
+    nsPtr->fullName = (char *) ckalloc((unsigned) (name_len+1));
     strcpy(nsPtr->fullName, name);
 
     Tcl_DStringFree(&buffer1);
@@ -3182,7 +3189,7 @@
 
     currNsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp);
     if (currNsPtr == (Namespace *) Tcl_GetGlobalNamespace(interp)) {
-	objPtr = Tcl_NewStringObj("::", -1);
+	objPtr = Tcl_NewStringObj("::", 2);
     } else {
 	objPtr = Tcl_NewStringObj(currNsPtr->fullName, -1);
     }
@@ -3223,6 +3230,7 @@
     Tcl_Obj *CONST objv[];	/* Argument objects. */
 {
     register Namespace *currNsPtr;
+    CONST char *name;
 
     if (objc != 2) {
 	Tcl_WrongNumArgs(interp, 2, objv, NULL);
@@ -3239,11 +3247,9 @@
      */
 
     currNsPtr = (Namespace *) Tcl_GetCurrentNamespace(interp);
-    if (currNsPtr == (Namespace *) Tcl_GetGlobalNamespace(interp)) {
-	Tcl_SetObjResult(interp, Tcl_NewStringObj("::", 2));
-    } else {
-	Tcl_SetObjResult(interp, Tcl_NewStringObj(currNsPtr->fullName, -1));
-    }
+    name = (currNsPtr == (Namespace *) Tcl_GetGlobalNamespace(interp))
+	    ? "::" : currNsPtr->fullName;
+    Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
     return TCL_OK;
 }
 
@@ -4627,18 +4633,15 @@
 {
     ResolvedNsName *resNamePtr =
 	    (ResolvedNsName *) objPtr->internalRep.otherValuePtr;
-    register Namespace *nsPtr;
     char *name = "";
-    int length;
+    int length = 0;
 
     if ((resNamePtr != NULL)
 	    && (resNamePtr->nsId == resNamePtr->nsPtr->nsId)) {
-	nsPtr = resNamePtr->nsPtr;
-	if (nsPtr->flags & NS_DEAD) {
-	    nsPtr = NULL;
-	}
-	if (nsPtr != NULL) {
+	Namespace *nsPtr = resNamePtr->nsPtr;
+	if (nsPtr != NULL && !(nsPtr->flags & NS_DEAD)) {
 	    name = nsPtr->fullName;
+	    length = strlen(name);
 	}
     }
 
@@ -4647,7 +4650,6 @@
      * if the internal rep is NULL.
      */
 
-    length = strlen(name);
     if (length == 0) {
 	objPtr->bytes = tclEmptyStringRep;
     } else {
@@ -4971,11 +4973,9 @@
 	    Tcl_ListObjAppendElement(NULL, resultObj,
 		    Tcl_NewStringObj(configOptions[CONF_MAP], -1));
 	    Tcl_GetEnsembleMappingDict(NULL, token, &tmpObj);
-	    if (tmpObj != NULL) {
-		Tcl_ListObjAppendElement(NULL, resultObj, tmpObj);
-	    } else {
-		Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewObj());
-	    }
+	    Tcl_ListObjAppendElement(NULL, resultObj,
+		    tmpObj ? tmpObj : Tcl_NewObj());
+
 	    /* -namespace option */
 	    Tcl_ListObjAppendElement(NULL, resultObj,
 		    Tcl_NewStringObj(configOptions[CONF_NAMESPACE], -1));
@@ -4993,20 +4993,16 @@
 	    Tcl_ListObjAppendElement(NULL, resultObj,
 		    Tcl_NewStringObj(configOptions[CONF_SUBCMDS], -1));
 	    Tcl_GetEnsembleSubcommandList(NULL, token, &tmpObj);
-	    if (tmpObj != NULL) {
-		Tcl_ListObjAppendElement(NULL, resultObj, tmpObj);
-	    } else {
-		Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewObj());
-	    }
+	    Tcl_ListObjAppendElement(NULL, resultObj,
+		    tmpObj ? tmpObj : Tcl_NewObj());
+
 	    /* -unknown option */
 	    Tcl_ListObjAppendElement(NULL, resultObj,
 		    Tcl_NewStringObj(configOptions[CONF_UNKNOWN], -1));
 	    Tcl_GetEnsembleUnknownHandler(NULL, token, &tmpObj);
-	    if (tmpObj != NULL) {
-		Tcl_ListObjAppendElement(NULL, resultObj, tmpObj);
-	    } else {
-		Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewObj());
-	    }
+	    Tcl_ListObjAppendElement(NULL, resultObj,
+		    tmpObj ? tmpObj : Tcl_NewObj());
+
 	    Tcl_SetObjResult(interp, resultObj);
 	    return TCL_OK;
 
