diff options
author | dgp <dgp@users.sourceforge.net> | 2017-06-05 20:03:19 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2017-06-05 20:03:19 (GMT) |
commit | 735ced34c942925be92107aa7752ab143eaf6fb2 (patch) | |
tree | e50cf5428a86f6878ce10162df99ecec2cf2a9ab /generic | |
parent | 21ad2c33e88cdca35006778053c71100709ccea8 (diff) | |
download | tcl-735ced34c942925be92107aa7752ab143eaf6fb2.zip tcl-735ced34c942925be92107aa7752ab143eaf6fb2.tar.gz tcl-735ced34c942925be92107aa7752ab143eaf6fb2.tar.bz2 |
Optimize TclStringCatObjv() for case when only one argument is non-empty.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclStringObj.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 3478cbb..a4c242a 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2848,7 +2848,7 @@ TclStringCatObjv( Tcl_Obj **objPtrPtr) { Tcl_Obj *objPtr, *objResultPtr, * const *ov; - int oc, length = 0, binary = 1, first = 0; + int oc, length = 0, binary = 1, first = 0, last = 0; int allowUniChar = 1, requestUniChar = 0; /* assert (objc >= 2) */ @@ -2904,8 +2904,11 @@ TclStringCatObjv( int numBytes; Tcl_GetByteArrayFromObj(objPtr, &numBytes); /* PANIC? */ - if (length == 0) { - first = objc - oc - 1; + if (numBytes) { + last = objc - oc - 1; + if (length == 0) { + first = last; + } } length += numBytes; } @@ -2920,8 +2923,11 @@ TclStringCatObjv( int numChars; Tcl_GetUnicodeFromObj(objPtr, &numChars); /* PANIC? */ - if (length == 0) { - first = objc - oc - 1; + if (numChars) { + last = objc - oc - 1; + if (length == 0) { + first = last; + } } length += numChars; } @@ -2935,8 +2941,11 @@ TclStringCatObjv( objPtr = *ov++; Tcl_GetStringFromObj(objPtr, &numBytes); /* PANIC? */ - if ((length == 0) && numBytes) { - first = objc - oc - 1; + if (numBytes) { + last = objc - oc - 1; + if (length == 0) { + first = last; + } } length += numBytes; } @@ -2956,8 +2965,13 @@ TclStringCatObjv( *objPtrPtr = objv[0]; return TCL_OK; } + if (last == first) { + /* Only one non-empty value; return it */ + *objPtrPtr = objv[first]; + return TCL_OK; + } - objv += first; objc -= first; + objv += first; objc = (last - first + 1); if (binary) { /* Efficiently produce a pure byte array result */ |