diff options
author | dgp <dgp@noemail.net> | 2011-05-02 15:44:14 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2011-05-02 15:44:14 (GMT) |
commit | 8365646a059cea678b9c5c89496441ac714662f0 (patch) | |
tree | d01cce7427e718ba1d1a2717b5e98f1c8c63154d /generic/tclListObj.c | |
parent | 2069db38ed673bcae513abca4c710e2a90bd1053 (diff) | |
parent | cbb19a69c6f78ac08e9ef00997d7ce2de3b751da (diff) | |
download | tcl-8365646a059cea678b9c5c89496441ac714662f0.zip tcl-8365646a059cea678b9c5c89496441ac714662f0.tar.gz tcl-8365646a059cea678b9c5c89496441ac714662f0.tar.bz2 |
Replace TclCountSpaceRuns() with TclMaxListLength() which is the function we
actually want.
FossilOrigin-Name: 304fa3c29b1d28dcb2466e6818ed9db9c9b75c89
Diffstat (limited to 'generic/tclListObj.c')
-rw-r--r-- | generic/tclListObj.c | 20 |
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++) { |