Tcl Source Code

Check-in [af5aec752d]
Login

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

Overview
Comment:Use local variables.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: af5aec752d019b5c5265ae3ce8debf778746da1f
User & Date: dgp 2017-06-16 14:46:56
Context
2017-06-16
15:51
Factor out and simplify loop scanning leading known empty values. check-in: 1e6a22b0fc user: dgp tags: trunk
14:46
Use local variables. check-in: af5aec752d user: dgp tags: trunk
14:43
Rework the logic. Equivalent function. check-in: aa9699939f user: dgp tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
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;
    int allowUniChar = 1, requestUniChar = 0;
    int first = objc - 1;	/* Index of first value possibly not empty */
    int last = 0;		/* Index of last value possibly not empty */

    /* assert ( objc >= 0 ) */








|







2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
TclStringCatObjv(
    Tcl_Interp *interp,
    int inPlace,
    int objc,
    Tcl_Obj * const objv[],
    Tcl_Obj **objPtrPtr)
{
    Tcl_Obj *objResultPtr, * const *ov;
    int oc, length = 0, binary = 1;
    int allowUniChar = 1, requestUniChar = 0;
    int first = objc - 1;	/* Index of first value possibly not empty */
    int last = 0;		/* Index of last value possibly not empty */

    /* assert ( objc >= 0 ) */

2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
     * GOALS:	Avoid shimmering & string rep generation.
     * 		Produce pure bytearray when possible.
     * 		Error on overflow.
     */

    ov = objv, oc = objc;
    do {
	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







|







2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
     * GOALS:	Avoid shimmering & string rep generation.
     * 		Produce pure bytearray when possible.
     * 		Error on overflow.
     */

    ov = objv, oc = objc;
    do {
	Tcl_Obj *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
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
	}
    } while (--oc && (binary || allowUniChar));

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

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

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

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

		Tcl_GetUnicodeFromObj(objPtr, &numChars); /* PANIC? */
		if (numChars) {
		    last = objc - oc;







|




















|







2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
	}
    } while (--oc && (binary || allowUniChar));

    if (binary) {
	/* Result will be pure byte array. Pre-size it */
	ov = objv; oc = objc;
	do {
	    Tcl_Obj *objPtr = *ov++;

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

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

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

		Tcl_GetUnicodeFromObj(objPtr, &numChars); /* PANIC? */
		if (numChars) {
		    last = objc - oc;
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
	Tcl_Obj *pendingPtr = NULL;

	/* Result will be concat of string reps. Pre-size it. */
	ov = objv; oc = objc;
	do {
	    int numBytes;

	    objPtr = *ov++;

	    if ((length == 0) && (objPtr->bytes == NULL) && !pendingPtr) {
		/* No string rep; Take the chance we can avoid making it */

		last = objc - oc;
		first = last;
		pendingPtr = objPtr;







|







2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
	Tcl_Obj *pendingPtr = NULL;

	/* Result will be concat of string reps. Pre-size it. */
	ov = objv; oc = objc;
	do {
	    int numBytes;

	    Tcl_Obj *objPtr = *ov++;

	    if ((length == 0) && (objPtr->bytes == NULL) && !pendingPtr) {
		/* No string rep; Take the chance we can avoid making it */

		last = objc - oc;
		first = last;
		pendingPtr = objPtr;