diff options
author | dgp <dgp@users.sourceforge.net> | 2016-10-31 18:10:21 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-10-31 18:10:21 (GMT) |
commit | b550e65a968434e0f17d097f85df3fb64347e1ce (patch) | |
tree | 8df14686aed1001cc9aaf678afbbf7ca533f503e | |
parent | 77c9a433f701214eafd76617a8e3c67316ebf08e (diff) | |
download | tcl-b550e65a968434e0f17d097f85df3fb64347e1ce.zip tcl-b550e65a968434e0f17d097f85df3fb64347e1ce.tar.gz tcl-b550e65a968434e0f17d097f85df3fb64347e1ce.tar.bz2 |
Reduce copies in the pure binary implementation of [string cat].
-rw-r--r-- | generic/tclStringObj.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index c0d85a0..1723804 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2688,18 +2688,21 @@ TclStringCatObjv( } objv += first; objc -= first; - objResultPtr = *objv++; objc--; - if (!inPlace || Tcl_IsShared(objResultPtr)) { - objResultPtr = Tcl_DuplicateObj(objResultPtr); - } if (binary) { /* Efficiently produce a pure binary result */ unsigned char *dst; - int start; - Tcl_GetByteArrayFromObj(objResultPtr, &start); - dst = Tcl_SetByteArrayLength(objResultPtr, length) + start; + if (inPlace && !Tcl_IsShared(*objv)) { + int start; + + objResultPtr = *objv++; objc--; + Tcl_GetByteArrayFromObj(objResultPtr, &start); + dst = Tcl_SetByteArrayLength(objResultPtr, length) + start; + } else { + objResultPtr = Tcl_NewByteArrayObj(NULL, length); + dst = Tcl_SetByteArrayLength(objResultPtr, length); + } while (objc--) { Tcl_Obj *objPtr = *objv++; @@ -2711,6 +2714,15 @@ TclStringCatObjv( } } } else { + + + objResultPtr = *objv++; objc--; + if (!inPlace || Tcl_IsShared(objResultPtr)) { + objResultPtr = Tcl_DuplicateObj(objResultPtr); + } + + + while (objc--) { Tcl_AppendObjToObj(objResultPtr, *objv++); } |