summaryrefslogtreecommitdiffstats
path: root/generic/tclDictObj.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclDictObj.c')
-rw-r--r--generic/tclDictObj.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c
index f99f984..9686c6f 100644
--- a/generic/tclDictObj.c
+++ b/generic/tclDictObj.c
@@ -2282,7 +2282,7 @@ DictAppendCmd(
Tcl_Obj *const *objv)
{
Tcl_Obj *dictPtr, *valuePtr, *resultPtr;
- int i, allocatedDict = 0;
+ int allocatedDict = 0;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "dictVarName key ?value ...?");
@@ -2307,15 +2307,33 @@ DictAppendCmd(
if ((objc > 3) || (valuePtr == NULL)) {
/* Only go through append activites when something will change. */
+ Tcl_Obj *appendObjPtr = NULL;
- if (valuePtr == NULL) {
+ if (objc > 3) {
+ /* Something to append */
+
+ if (objc == 4) {
+ appendObjPtr = objv[3];
+ } else if (TCL_OK != TclStringCatObjv(interp, /* inPlace */ 1,
+ objc-3, objv+3, &appendObjPtr)) {
+ return TCL_ERROR;
+ }
+ }
+
+ if (appendObjPtr == NULL) {
+ /* => (objc == 3) => (valuePtr == NULL) */
TclNewObj(valuePtr);
- } else if (Tcl_IsShared(valuePtr)) {
- valuePtr = Tcl_DuplicateObj(valuePtr);
+ } else if (valuePtr == NULL) {
+ valuePtr = appendObjPtr;
+ appendObjPtr = NULL;
}
- for (i=3 ; i<objc ; i++) {
- Tcl_AppendObjToObj(valuePtr, objv[i]);
+ if (appendObjPtr) {
+ if (Tcl_IsShared(valuePtr)) {
+ valuePtr = Tcl_DuplicateObj(valuePtr);
+ }
+
+ Tcl_AppendObjToObj(valuePtr, appendObjPtr);
}
Tcl_DictObjPut(NULL, dictPtr, objv[2], valuePtr);