Tcl Source Code

Check-in [e9f3293d67]
Login

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

Overview
Comment:Another reworking, now with comments.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9f3293d6764e394de0606574eaa8536d4f0309c
User & Date: dgp 2017-06-16 19:54:57
Context
2017-06-18
18:02
Factor out chunk of non-obvious code in the guts of [oo::define] into one place. check-in: bbaad94279 user: dkf tags: trunk
2017-06-16
20:35
merge trunk check-in: f7688ef8a2 user: dgp tags: novem
20:28
merge trunk check-in: 2b4060cef5 user: dgp tags: tip-445
19:54
Another reworking, now with comments. check-in: e9f3293d67 user: dgp tags: trunk
16:23
Simplify the final loop when we know we're generating strings for all. check-in: 20cca1d020 user: dgp tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954








2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967







2968
2969
2970
2971
2972
2973
2974
2975

2976


2977

2978
2979
2980

2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
			goto overflow;
		    }
		    length += numChars;
		}
	    }
	} while (--oc);
    } else {
	Tcl_Obj *pendingPtr = NULL;

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








	    /* assert ( pendingPtr == NULL ) */
	    /* assert ( length == 0 ) */

	    Tcl_Obj *objPtr = *ov++;

	    if (objPtr->bytes == NULL) {
		/* No string rep; Take the chance we can avoid making it */
		pendingPtr = objPtr;
	    } else {
		Tcl_GetStringFromObj(objPtr, &length); /* PANIC? */
	    }
	} while (--oc && (length == 0) && (pendingPtr == NULL));








	first = last = objc - oc - 1;

	while (oc && (length == 0)) {
	    int numBytes;
	    Tcl_Obj *objPtr = *ov++;

	    /* assert ( pendingPtr != NULL ) <-- aiming for */


	    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;
	    } else {

		Tcl_GetStringFromObj(objPtr, &numBytes); /* PANIC? */
		if (numBytes) {
		    last = objc - oc;
		} else if (pendingPtr == NULL || pendingPtr->bytes == NULL) {
		    --oc;
		    continue;
		}
		if (pendingPtr) {
		    Tcl_GetStringFromObj(pendingPtr, &length); /* PANIC? */
		    pendingPtr = NULL;
		}
		if (length == 0) {
		    if (numBytes) {
			first = last;
		    } else {
			first = objc - 1;
			last = 0;
		    }
		} else if (numBytes > INT_MAX - length) {
		    goto overflow;
		}
		length += numBytes;
	    }
	    --oc;
	}

	while (oc) {
	    int numBytes;
	    Tcl_Obj *objPtr = *ov++;

	    /* assert ( length > 0 && pendingPtr == NULL )  */








<
<



>
>
>
>
>
>
>
>
|
|

|

|
|
|
|
|
|
|

>
>
>
>
>
>
>
|

|
|
<

|

>
|
>
>
|
>

|
|
>
|
<

<

|
<
<
<

|
|
<




<
<
<






|
<







2943
2944
2945
2946
2947
2948
2949


2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984

2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998

2999

3000
3001



3002
3003
3004

3005
3006
3007
3008



3009
3010
3011
3012
3013
3014
3015

3016
3017
3018
3019
3020
3021
3022
			goto overflow;
		    }
		    length += numChars;
		}
	    }
	} while (--oc);
    } else {


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

	    /*
	     * Loop until a possibly non-empty value is reached.
	     * Keep string rep generation pending when possible.
	     */

	    do {
		/* assert ( pendingPtr == NULL ) */
		/* assert ( length == 0 ) */

		Tcl_Obj *objPtr = *ov++;

		if (objPtr->bytes == NULL) {
		    /* No string rep; Take the chance we can avoid making it */
		    pendingPtr = objPtr;
		} else {
		    Tcl_GetStringFromObj(objPtr, &length); /* PANIC? */
		}
	    } while (--oc && (length == 0) && (pendingPtr == NULL));

	    /*
 	     * Either we found a possibly non-empty value, and we
 	     * remember this index as the first and last such value so
 	     * far seen, or (oc == 0) and all values are known empty,
 	     * so first = last = objc - 1 signals the right quick return.
 	     */

	    first = last = objc - oc - 1;

	    if (oc && (length == 0)) {
		int numBytes;


		/* assert ( pendingPtr != NULL ) */

		/*
		 * There's a pending value followed by more values.
		 * Loop over remaining values generating strings until
		 * a non-empty value is found, or the pending value gets
		 * its string generated.
		 */

		do {
		    Tcl_Obj *objPtr = *ov++;
		    Tcl_GetStringFromObj(objPtr, &numBytes); /* PANIC? */
		} while (--oc && numBytes == 0 && pendingPtr->bytes == NULL);



		if (numBytes) {
		    last = objc -oc -1;



		}
		if (oc || numBytes) {
		    Tcl_GetStringFromObj(pendingPtr, &length);

		}
		if (length == 0) {
		    if (numBytes) {
			first = last;



		    }
		} else if (numBytes > INT_MAX - length) {
		    goto overflow;
		}
		length += numBytes;
	    }
	} while (oc && (length == 0));


	while (oc) {
	    int numBytes;
	    Tcl_Obj *objPtr = *ov++;

	    /* assert ( length > 0 && pendingPtr == NULL )  */