Tcl Source Code

Check-in [70c49b9302]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More optimized non-BC [string cat] using Tcl_AppendObjToObj() - thx Donal
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-429
Files: files | file ages | folders
SHA1: 70c49b9302f56f1682c3c9f70050451f6475d10d
User & Date: ferrieux 2014-08-05 09:55:54
Context
2014-08-05
10:34
Add constant folding to [string cat]. Mixed-quote idiom is now compiled to a single push. check-in: a321e41d54 user: ferrieux tags: tip-429
09:55
More optimized non-BC [string cat] using Tcl_AppendObjToObj() - thx Donal check-in: 70c49b9302 user: ferrieux tags: tip-429
2014-08-04
14:06
Hum. Really merge trunk. check-in: 5d9c445fc1 user: ferrieux tags: tip-429
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclCmdMZ.c.

2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881

2882
2883

2884

2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899

2900


2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
static int
StringCatCmd(
    ClientData dummy,		/* Not used. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int tot, i, length;
    char *bytes, *p;
    Tcl_Obj *objResultPtr;

    /*
     * NOTE: this implementation aims for simplicity, not speed, because all
     * speed-critical uses of [string cat] will involve the compiled variant
     * anyway. Thus we avoid code duplication (from TEBC/INST_CONCAT1) without
     * sacrificing perf.
     */
	
    if (objc < 2) {
	/*
	 * If there are no args, the result is an empty object.
	 * Just leave the preset empty interp result.
	 */
	return TCL_OK;
    }
    tot = 0;
    for(i = 1;i < objc;i++) {

	bytes = TclGetStringFromObj(objv[i], &length);
	if (bytes != NULL) {

	    tot += length;

	}
    }
    if (tot < 0) {
	/* TODO: convert panic to error ? */
	Tcl_Panic("max size for a Tcl value (%d bytes) exceeded", INT_MAX);
    }
    p = ckalloc(tot + 1);
    TclNewObj(objResultPtr);
    objResultPtr->bytes = p;
    objResultPtr->length = tot;
    for (i = 1;i < objc;i++) {
	bytes = TclGetStringFromObj(objv[i], &length);
	if (bytes != NULL) {
	    memcpy(p, bytes, (size_t) length);
	    p += length;

	}


    }
    *p = '\0';
    Tcl_SetObjResult(interp,objResultPtr);
    
    return TCL_OK;
}
 
/*
 *----------------------------------------------------------------------
 *






|
<


<
<
<
<
<
<
<







|
<
>
|
<
>
|
>
|
<
<
<
<
<
<
|
|
<
<
<
<
<
<
>
|
>
>

<
|







2855
2856
2857
2858
2859
2860
2861
2862

2863
2864







2865
2866
2867
2868
2869
2870
2871
2872

2873
2874

2875
2876
2877
2878






2879
2880






2881
2882
2883
2884
2885

2886
2887
2888
2889
2890
2891
2892
2893
static int
StringCatCmd(
    ClientData dummy,		/* Not used. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    int i;

    Tcl_Obj *objResultPtr;








    if (objc < 2) {
	/*
	 * If there are no args, the result is an empty object.
	 * Just leave the preset empty interp result.
	 */
	return TCL_OK;
    }
    if (objc == 2) {

	/*
	 * Other trivial case, single arg, just return it.

	 */
	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]);
    }

    Tcl_SetObjResult(interp, objResultPtr);
    
    return TCL_OK;
}
 
/*
 *----------------------------------------------------------------------
 *