summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-10-27 19:39:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-10-27 19:39:49 (GMT)
commitec332750d28a86537a3fc721decc3bb74d850dc9 (patch)
tree1265709e60aa38ed6a1ffd00d7660d9f17e13cce /generic
parente4a82e14e114848e09bb17073c531eba791aacee (diff)
downloadtcl-ec332750d28a86537a3fc721decc3bb74d850dc9.zip
tcl-ec332750d28a86537a3fc721decc3bb74d850dc9.tar.gz
tcl-ec332750d28a86537a3fc721decc3bb74d850dc9.tar.bz2
Start bringing all `string cat` operations into one place so it can be coded
correctly one time instead of badly multiple times.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCmdMZ.c17
-rw-r--r--generic/tclInt.h2
-rw-r--r--generic/tclStringObj.c40
3 files changed, 50 insertions, 9 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index 591e31c..1a08674 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -2855,7 +2855,7 @@ StringCatCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
{
- int i;
+ int code;
Tcl_Obj *objResultPtr;
if (objc < 2) {
@@ -2872,16 +2872,15 @@ StringCatCmd(
Tcl_SetObjResult(interp, objv[1]);
return TCL_OK;
}
- objResultPtr = objv[1];
- if (Tcl_IsShared(objResultPtr)) {
- objResultPtr = Tcl_DuplicateObj(objResultPtr);
- }
- for(i = 2;i < objc;i++) {
- Tcl_AppendObjToObj(objResultPtr, objv[i]);
+
+ code = TclStringCatObjv(interp, objc-1, objv+1, &objResultPtr);
+
+ if (code == TCL_OK) {
+ Tcl_SetObjResult(interp, objResultPtr);
+ return TCL_OK;
}
- Tcl_SetObjResult(interp, objResultPtr);
- return TCL_OK;
+ return code;
}
/*
diff --git a/generic/tclInt.h b/generic/tclInt.h
index da1b5c5..36c1a81 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3135,6 +3135,8 @@ MODULE_SCOPE void TclSpellFix(Tcl_Interp *interp,
Tcl_Obj *bad, Tcl_Obj *fix);
MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr,
int numBytes);
+MODULE_SCOPE int TclStringCatObjv(Tcl_Interp *interp, int objc,
+ Tcl_Obj *const objv[], Tcl_Obj **objPtrPtr);
MODULE_SCOPE int TclStringMatch(const char *str, int strLen,
const char *pattern, int ptnLen, int flags);
MODULE_SCOPE int TclStringMatchObj(Tcl_Obj *stringObj,
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 2930fa1..1828d20 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -2598,6 +2598,46 @@ TclGetStringStorage(
*sizePtr = stringPtr->allocated;
return objPtr->bytes;
}
+
+/*
+ *---------------------------------------------------------------------------
+ *
+ * TclStringCatObjv --
+ *
+ * Performs the [string cat] function.
+ *
+ * Results:
+ * A standard Tcl result.
+ *
+ * Side effects:
+ * Writes to *objPtrPtr the address of Tcl_Obj that is concatenation
+ * of all objc values in objv.
+ *
+ *---------------------------------------------------------------------------
+ */
+
+int
+TclStringCatObjv(
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj * const objv[],
+ Tcl_Obj **objPtrPtr)
+{
+ Tcl_Obj *objResultPtr;
+
+ /* assert (objc >= 2) */
+
+ objResultPtr = *objv++; objc--;
+ if (Tcl_IsShared(objResultPtr)) {
+ objResultPtr = Tcl_DuplicateObj(objResultPtr);
+ }
+ while (objc--) {
+ Tcl_AppendObjToObj(objResultPtr, *objv++);
+ }
+ *objPtrPtr = objResultPtr;
+ return TCL_OK;
+}
+
/*
*---------------------------------------------------------------------------
*