Tcl Source Code

Check-in [20cca1d020]
Login

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

Overview
Comment:Simplify the final loop when we know we're generating strings for all.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 20cca1d020399042bf9078ef5836f175441cc702
User & Date: dgp 2017-06-16 16:23:22
Context
2017-06-16
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
16:07
Split loop into two cases for further simplification. check-in: afd6a2812b user: dgp tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
		    goto overflow;
		}
		length += numBytes;
	    }
	    --oc;
	}

      if (oc) {

	/* assert ( length > 0 )  */


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

		Tcl_GetStringFromObj(objPtr, &numBytes); /* PANIC? */
		if (numBytes) {
		    last = objc - oc;
		} else if (pendingPtr == NULL || pendingPtr->bytes == NULL) {
		    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;
	    }
	} while (--oc);
      }
    }

    if (last <= first /*|| length == 0 */) {
	/* Only one non-empty value or zero length; return first */
	/* NOTE: (length == 0) implies (last <= first) */
	*objPtrPtr = objv[first];
	return TCL_OK;







|
<
<
<
<
<

<


<
<
<
<
<
|
<

|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|




|
|







3003
3004
3005
3006
3007
3008
3009
3010





3011

3012
3013





3014

3015
3016
3017
3018














3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
		    goto overflow;
		}
		length += numBytes;
	    }
	    --oc;
	}

	while (oc) {





	    int numBytes;

	    Tcl_Obj *objPtr = *ov++;






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


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














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

    if (last <= first /*|| length == 0 */) {
	/* Only one non-empty value or zero length; return first */
	/* NOTE: (length == 0) implies (last <= first) */
	*objPtrPtr = objv[first];
	return TCL_OK;