summaryrefslogtreecommitdiffstats
path: root/generic/tclDictObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-10-28 16:55:44 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-10-28 16:55:44 (GMT)
commit29038829dceb276e2d15cae2097f302f46eb272f (patch)
treef080b244d3728d82ff7329bfa0e3760249e361c3 /generic/tclDictObj.c
parent008dd7e2517ec526af573528879663f392bc3ac3 (diff)
downloadtcl-29038829dceb276e2d15cae2097f302f46eb272f.zip
tcl-29038829dceb276e2d15cae2097f302f46eb272f.tar.gz
tcl-29038829dceb276e2d15cae2097f302f46eb272f.tar.bz2
revise [dict append] to make use of common [string cat] engine.
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..3be968a 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, 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);