diff options
author | dgp <dgp@users.sourceforge.net> | 2016-10-28 15:46:49 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-10-28 15:46:49 (GMT) |
commit | dff4ed85a2e6fac50d5e9d7caee4a7f1dffcd835 (patch) | |
tree | 4867fc357b70ce1cd59ab18b2d8d3504a1981bce /generic/tclDictObj.c | |
parent | 335716b81d99c7476e68979fe48b20b0f2bfeeee (diff) | |
download | tcl-dff4ed85a2e6fac50d5e9d7caee4a7f1dffcd835.zip tcl-dff4ed85a2e6fac50d5e9d7caee4a7f1dffcd835.tar.gz tcl-dff4ed85a2e6fac50d5e9d7caee4a7f1dffcd835.tar.bz2 |
Add optimization to [dict append].
Diffstat (limited to 'generic/tclDictObj.c')
-rw-r--r-- | generic/tclDictObj.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index 428173d..f99f984 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -2305,17 +2305,26 @@ DictAppendCmd( return TCL_ERROR; } - if (valuePtr == NULL) { - TclNewObj(valuePtr); - } else if (Tcl_IsShared(valuePtr)) { - valuePtr = Tcl_DuplicateObj(valuePtr); - } + if ((objc > 3) || (valuePtr == NULL)) { + /* Only go through append activites when something will change. */ + + if (valuePtr == NULL) { + TclNewObj(valuePtr); + } else if (Tcl_IsShared(valuePtr)) { + valuePtr = Tcl_DuplicateObj(valuePtr); + } - for (i=3 ; i<objc ; i++) { - Tcl_AppendObjToObj(valuePtr, objv[i]); + for (i=3 ; i<objc ; i++) { + Tcl_AppendObjToObj(valuePtr, objv[i]); + } + + Tcl_DictObjPut(NULL, dictPtr, objv[2], valuePtr); } - Tcl_DictObjPut(NULL, dictPtr, objv[2], valuePtr); + /* + * Even if nothing changed, we still overwrite so that variable + * trace expectations are met. + */ resultPtr = Tcl_ObjSetVar2(interp, objv[1], NULL, dictPtr, TCL_LEAVE_ERR_MSG); |