summaryrefslogtreecommitdiffstats
path: root/generic/tclListObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-05-02 15:38:31 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-05-02 15:38:31 (GMT)
commitef87219015417dcab0f3aae83834c2c00cdb5607 (patch)
tree157fb830c0521a0dfee6f61d29b92b1153f3c44b /generic/tclListObj.c
parent98b8497049cfeef401ed6514580249aac3383d4e (diff)
downloadtcl-ef87219015417dcab0f3aae83834c2c00cdb5607.zip
tcl-ef87219015417dcab0f3aae83834c2c00cdb5607.tar.gz
tcl-ef87219015417dcab0f3aae83834c2c00cdb5607.tar.bz2
Replace TclCountSpaceRuns() with TclMaxListLength() which is the function we
actually want.
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 d3465b0..1fabcab 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -1759,27 +1759,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++) {