summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-04-22 16:29:07 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-04-22 16:29:07 (GMT)
commit39180cad0ef18a8bda37c082bac7bd3297bc9345 (patch)
tree32c779585ad0c676ee5d833b2a3b5d4557e09254 /generic/tclStringObj.c
parent79af33ce68d41dfa9f864eb74c0ad637ef320565 (diff)
downloadtcl-39180cad0ef18a8bda37c082bac7bd3297bc9345.zip
tcl-39180cad0ef18a8bda37c082bac7bd3297bc9345.tar.gz
tcl-39180cad0ef18a8bda37c082bac7bd3297bc9345.tar.bz2
Backout [4a7b807856], It breaks the build. See: [https://github.com/tcltk/tcl/actions/runs/4771586851/jobs/8483606969]
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c61
1 files changed, 33 insertions, 28 deletions
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);