summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-06-06 09:25:00 (GMT)
committersebres <sebres@users.sourceforge.net>2017-06-06 09:25:00 (GMT)
commit47558a128c45f7915b69e10652573089efc3a897 (patch)
tree1215208c58595364a0fabc70662064ad5a5e1b51 /generic
parent449b9c2c29e600d4e02c0430f360262aabc2ddb7 (diff)
downloadtcl-47558a128c45f7915b69e10652573089efc3a897.zip
tcl-47558a128c45f7915b69e10652573089efc3a897.tar.gz
tcl-47558a128c45f7915b69e10652573089efc3a897.tar.bz2
makes TclStringCatObjv safe accepting objc = 0 (or 1), then fast exits with new object / first; check-cycles rewritten to be still more faster.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclStringObj.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 6332e9f..b78394e 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -2851,7 +2851,11 @@ TclStringCatObjv(
int oc, length = 0, binary = 1, first = 0, last = 0;
int allowUniChar = 1, requestUniChar = 0;
- /* assert (objc >= 2) */
+ if (objc <= 1) {
+ /* Only one or no objects; return first or empty */
+ *objPtrPtr = objc ? objv[0] : Tcl_NewObj();
+ return TCL_OK;
+ }
/*
* Analyze to determine what representation result should be.
@@ -2861,7 +2865,7 @@ TclStringCatObjv(
*/
ov = objv, oc = objc;
- while (oc-- && (binary || allowUniChar)) {
+ do {
objPtr = *ov++;
if (objPtr->bytes) {
@@ -2892,12 +2896,12 @@ TclStringCatObjv(
}
}
}
- }
+ } while (--oc && (binary || allowUniChar));
if (binary) {
/* Result will be pure byte array. Pre-size it */
ov = objv; oc = objc;
- while (oc--) {
+ do {
objPtr = *ov++;
if (objPtr->bytes == NULL) {
@@ -2905,7 +2909,7 @@ TclStringCatObjv(
Tcl_GetByteArrayFromObj(objPtr, &numBytes); /* PANIC? */
if (numBytes) {
- last = objc - oc - 1;
+ last = objc - oc;
if (length == 0) {
first = last;
}
@@ -2914,11 +2918,11 @@ TclStringCatObjv(
}
}
}
- }
+ } while (--oc);
} else if (allowUniChar && requestUniChar) {
/* Result will be pure Tcl_UniChar array. Pre-size it. */
ov = objv; oc = objc;
- while (oc--) {
+ do {
objPtr = *ov++;
if ((objPtr->bytes == NULL) || (objPtr->length)) {
@@ -2926,7 +2930,7 @@ TclStringCatObjv(
Tcl_GetUnicodeFromObj(objPtr, &numChars); /* PANIC? */
if (numChars) {
- last = objc - oc - 1;
+ last = objc - oc;
if (length == 0) {
first = last;
}
@@ -2935,18 +2939,18 @@ TclStringCatObjv(
}
}
}
- }
+ } while (--oc);
} else {
/* Result will be concat of string reps. Pre-size it. */
ov = objv; oc = objc;
- while (oc--) {
+ do {
int numBytes;
objPtr = *ov++;
Tcl_GetStringFromObj(objPtr, &numBytes); /* PANIC? */
if (numBytes) {
- last = objc - oc - 1;
+ last = objc - oc;
if (length == 0) {
first = last;
}
@@ -2954,7 +2958,7 @@ TclStringCatObjv(
break; /* overflow */
}
}
- }
+ } while (--oc);
}
if (last == first || length == 0) {