summaryrefslogtreecommitdiffstats
path: root/generic/tclListObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-05-02 15:44:14 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-05-02 15:44:14 (GMT)
commit0460c501692feb12cd4c0198e99712a9ccc5d5eb (patch)
treed01cce7427e718ba1d1a2717b5e98f1c8c63154d /generic/tclListObj.c
parentf24cdf4341465ea638b1d195d2ae99f4fc0eb163 (diff)
parentef87219015417dcab0f3aae83834c2c00cdb5607 (diff)
downloadtcl-0460c501692feb12cd4c0198e99712a9ccc5d5eb.zip
tcl-0460c501692feb12cd4c0198e99712a9ccc5d5eb.tar.gz
tcl-0460c501692feb12cd4c0198e99712a9ccc5d5eb.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 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++) {