Tcl Source Code

Check-in [78ef6f929b]
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:Replace indexing with pointer increments.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dgp-string-cat
Files: files | file ages | folders
SHA1: 78ef6f929b01ff677cbee9a9df6e5404413e560a
User & Date: dgp 2016-11-01 15:42:50
Context
2016-11-01
16:18
Refactor to channel all [string cat] functions through a single implementation. check-in: 5be62a44d4 user: dgp tags: trunk
15:42
Replace indexing with pointer increments. Closed-Leaf check-in: 78ef6f929b user: dgp tags: dgp-string-cat
15:12
Trim away obsolete code. check-in: 8c1453cc30 user: dgp tags: dgp-string-cat
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650

2651
2652
2653
2654
2655
2656
2657
2658
2659
....
2679
2680
2681
2682
2683
2684
2685
2686

2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701

2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718


2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
TclStringCatObjv(
    Tcl_Interp *interp,
    int inPlace,
    int objc,
    Tcl_Obj * const objv[],
    Tcl_Obj **objPtrPtr)
{
    Tcl_Obj *objResultPtr;
    int i, length = 0, binary = 1, first = 0;
    int allowUniChar = 1, requestUniChar = 0;

    /* assert (objc >= 2) */

    /*
     * Analyze to determine what representation result should be.
     * GOALS:	Avoid shimmering & string rep generation.
     * 		Produce pure bytearray when possible.
     * 		Error on overflow.
     */


    for (i = 0; i < objc && (binary || allowUniChar); i++) {
	Tcl_Obj *objPtr = objv[i];

	if (objPtr->bytes) {
	    /* Value has a string rep. */
	    if (objPtr->length) {
		/*
		 * Non-empty string rep. Not a pure bytearray, so we 
		 * won't create a pure bytearray
................................................................................
		}
	    }
	}
    }

    if (binary) {
	/* Result will be pure byte array. Pre-size it */
        for (i = 0; i < objc && length >= 0; i++) {

	    Tcl_Obj *objPtr = objv[i];

	    if (objPtr->bytes == NULL) {
		int numBytes;

		Tcl_GetByteArrayFromObj(objPtr, &numBytes);
		if (length == 0) {
		    first = i;
		}
		length += numBytes;
	    }
	}
    } else if (allowUniChar && requestUniChar) {
	/* Result will be pure Tcl_UniChar array. Pre-size it. */
        for (i = 0; i < objc && length >= 0; i++) {

	    Tcl_Obj *objPtr = objv[i];

	    if ((objPtr->bytes == NULL) || (objPtr->length)) {
		int numChars;

		Tcl_GetUnicodeFromObj(objPtr, &numChars);
		if (length == 0) {
		    first = i;
		}
		length += numChars;
	    }
	}
    } else {
	/* Result will be concat of string reps. Pre-size it. */
        for (i = 0; i < objc && length >= 0; i++) {
	    Tcl_Obj *objPtr = objv[i];
	    int numBytes;



	    Tcl_GetStringFromObj(objPtr, &numBytes);
	    if ((length == 0) && numBytes) {
		first = i;
	    }
	    length += numBytes;
	}
    }

    if (length < 0) {
	if (interp) {






|
|











>
|
|







 







|
>
|






|






|
>
|






|






|
|

>
>



|







2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
....
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
TclStringCatObjv(
    Tcl_Interp *interp,
    int inPlace,
    int objc,
    Tcl_Obj * const objv[],
    Tcl_Obj **objPtrPtr)
{
    Tcl_Obj *objPtr, *objResultPtr, * const *ov;
    int oc, length = 0, binary = 1, first = 0;
    int allowUniChar = 1, requestUniChar = 0;

    /* assert (objc >= 2) */

    /*
     * Analyze to determine what representation result should be.
     * GOALS:	Avoid shimmering & string rep generation.
     * 		Produce pure bytearray when possible.
     * 		Error on overflow.
     */

    ov = objv, oc = objc;
    while (oc-- && (binary || allowUniChar)) {
	objPtr = *ov++;

	if (objPtr->bytes) {
	    /* Value has a string rep. */
	    if (objPtr->length) {
		/*
		 * Non-empty string rep. Not a pure bytearray, so we 
		 * won't create a pure bytearray
................................................................................
		}
	    }
	}
    }

    if (binary) {
	/* Result will be pure byte array. Pre-size it */
	ov = objv; oc = objc;
	while (oc-- && (length >= 0)) {
	    objPtr = *ov++;

	    if (objPtr->bytes == NULL) {
		int numBytes;

		Tcl_GetByteArrayFromObj(objPtr, &numBytes);
		if (length == 0) {
		    first = objc - oc - 1;
		}
		length += numBytes;
	    }
	}
    } else if (allowUniChar && requestUniChar) {
	/* Result will be pure Tcl_UniChar array. Pre-size it. */
	ov = objv; oc = objc;
	while (oc-- && (length >= 0)) {
	    objPtr = *ov++;

	    if ((objPtr->bytes == NULL) || (objPtr->length)) {
		int numChars;

		Tcl_GetUnicodeFromObj(objPtr, &numChars);
		if (length == 0) {
		    first = objc - oc - 1;
		}
		length += numChars;
	    }
	}
    } else {
	/* Result will be concat of string reps. Pre-size it. */
	ov = objv; oc = objc;
	while (oc-- && (length >= 0)) {
	    int numBytes;

	    objPtr = *ov++;

	    Tcl_GetStringFromObj(objPtr, &numBytes);
	    if ((length == 0) && numBytes) {
		first = objc - oc - 1;
	    }
	    length += numBytes;
	}
    }

    if (length < 0) {
	if (interp) {