From dff4ed85a2e6fac50d5e9d7caee4a7f1dffcd835 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 28 Oct 2016 15:46:49 +0000 Subject: Add optimization to [dict append]. --- generic/tclDictObj.c | 25 +++++++++++++++++-------- 1 file 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