From 39180cad0ef18a8bda37c082bac7bd3297bc9345 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 22 Apr 2023 16:29:07 +0000 Subject: Backout [4a7b807856], It breaks the build. See: [https://github.com/tcltk/tcl/actions/runs/4771586851/jobs/8483606969] --- doc/StringObj.3 | 2 +- generic/tclStringObj.c | 61 +++++++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/doc/StringObj.3 b/doc/StringObj.3 index b708298..d835140 100644 --- a/doc/StringObj.3 +++ b/doc/StringObj.3 @@ -115,7 +115,7 @@ The index of the last Unicode character in the Unicode range to be returned as a new value. If negative, take all characters up to the last one available. .AP Tcl_Obj *objPtr in/out -A pointer to a value to read, or to an unshared value to modify. +Points to a value to manipulate. .AP Tcl_Obj *appendObjPtr in The value to append to \fIobjPtr\fR in \fBTcl_AppendObjToObj\fR. .AP "Tcl_Size \&| int" *lengthPtr out diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 48344d7..2bbc4bc 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -551,8 +551,9 @@ TclCheckEmptyString( int Tcl_GetUniChar( - Tcl_Obj *objPtr, /* The object to get the Unicode character from. */ - Tcl_Size index) /* Get the index'th Unicode character. */ + Tcl_Obj *objPtr, /* The object to get the Unicode charater + * from. */ + Tcl_Size index) /* Get the index'th Unicode character. */ { String *stringPtr; int ch; @@ -562,8 +563,8 @@ Tcl_GetUniChar( } /* - * For a ByteArray object there is no need to convert to a string to - * perform the indexing operation. + * Optimize the case where we're really dealing with a ByteArray object + * we don't need to convert to a string to perform the indexing operation. */ if (TclIsPureByteArray(objPtr)) { @@ -577,7 +578,7 @@ Tcl_GetUniChar( } /* - * Must work with the object as a string. + * OK, need to work with the object as a string. */ SetStringFromAny(NULL, objPtr); @@ -623,8 +624,9 @@ Tcl_GetUniChar( int TclGetUniChar( - Tcl_Obj *objPtr, /* The object to get the Unicode character from. */ - Tcl_Size index) /* Get the index'th Unicode character. */ + Tcl_Obj *objPtr, /* The object to get the Unicode charater + * from. */ + Tcl_Size index) /* Get the index'th Unicode character. */ { int ch = 0; @@ -1403,13 +1405,17 @@ Tcl_AppendUnicodeToObj( *---------------------------------------------------------------------- * * Tcl_AppendObjToObj -- - * Appends the value of apppendObjPtr to objPtr, which must not be shared. + * + * This function appends the string rep of one object to another. + * "objPtr" cannot be a shared object. * * Results: * None. * * Side effects: - * IMPORTANT: Does not and MUST NOT shimmer appendObjPtr. + * The string rep of appendObjPtr is appended to the string + * representation of objPtr. + * IMPORTANT: This routine does not and MUST NOT shimmer appendObjPtr. * Callers are counting on that. * *---------------------------------------------------------------------- @@ -1417,35 +1423,34 @@ Tcl_AppendUnicodeToObj( void Tcl_AppendObjToObj( - Tcl_Obj *objPtr, /* Points to the value to append to. */ - Tcl_Obj *appendObjPtr) /* The value to append. */ + Tcl_Obj *objPtr, /* Points to the object to append to. */ + Tcl_Obj *appendObjPtr) /* Object to append. */ { String *stringPtr; Tcl_Size length = 0, numChars; Tcl_Size appendNumChars = TCL_INDEX_NONE; const char *bytes; - if (appendObjPtr->bytes == &tclEmptyString) { - return; - } + /* + * Special case: second object is standard-empty is fast case. We know + * that appending nothing to anything leaves that starting anything... + */ - if (objPtr->bytes == &tclEmptyString) { - TclSetDuplicateObj(objPtr, appendObjPtr); + if (appendObjPtr->bytes == &tclEmptyString) { return; } - if ( - TclIsPureByteArray(appendObjPtr) - && (TclIsPureByteArray(objPtr) || objPtr->bytes == &tclEmptyString) - ) { - /* - * Both bytearray objects are pure. Therefore they faithfully - * represent the true values, making it safe to append the second - * bytearray to the first. - */ + /* + * Handle append of one ByteArray object to another as a special case. + * Note that we only do this when the objects are pure so that the + * bytearray faithfully represent the true value; Otherwise appending the + * byte arrays together could lose information; + */ + if ((TclIsPureByteArray(objPtr) || objPtr->bytes == &tclEmptyString) + && TclIsPureByteArray(appendObjPtr)) { /* - * One might expect the code here to be + * You might expect the code here to be * * bytes = Tcl_GetByteArrayFromObj(appendObjPtr, &length); * TclAppendBytesToByteArray(objPtr, bytes, length); @@ -3370,7 +3375,7 @@ TclStringCat( objResultPtr = *objv++; objc--; - /* Ugly interface! Force resize of the Unicode array. */ + /* Ugly interface! Force resize of the unicode array. */ (void)Tcl_GetUnicodeFromObj(objResultPtr, &start); Tcl_InvalidateStringRep(objResultPtr); if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) { @@ -4209,7 +4214,7 @@ TclStringReplace( static void FillUnicodeRep( - Tcl_Obj *objPtr) /* The object in which to fill the Unicode + Tcl_Obj *objPtr) /* The object in which to fill the unicode * rep. */ { String *stringPtr = GET_STRING(objPtr); -- cgit v0.12