summaryrefslogtreecommitdiffstats
path: root/generic/tclListObj.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclListObj.c')
-rw-r--r--generic/tclListObj.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index 9437f7e..03843b8 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -1783,27 +1783,21 @@ SetListFromAny(
/*
* Parse the string into separate string objects, and create a List
- * structure that points to the element string objects. We use a modified
- * version of Tcl_SplitList's implementation to avoid one malloc and a
- * string copy for each list element. First, estimate the number of
- * elements by counting the number of space characters in the list.
- */
-
- estCount = TclCountSpaceRuns(string, length, &limit) + 1;
-
- /*
- * Allocate a new List structure with enough room for "estCount" elements.
- * Each element is a pointer to a Tcl_Obj with the appropriate string rep.
- * The initial "estCount" elements are set using the corresponding "argv"
- * strings.
+ * structure that points to the element string objects.
+ *
+ * First, allocate enough space to hold a (Tcl_Obj *) for each
+ * (possible) list element.
*/
+ estCount = TclMaxListLength(string, length, &limit);
+ estCount += (estCount == 0); /* Smallest List struct holds 1 element. */
listRepPtr = AttemptNewList(interp, estCount, NULL);
if (listRepPtr == NULL) {
return TCL_ERROR;
}
elemPtrs = &listRepPtr->elements;
+ /* Each iteration, parse and store a list element */
for (p=string, lenRemain=length, i=0;
lenRemain > 0;
p=nextElem, lenRemain=limit-nextElem, i++) {