diff options
author | dgp <dgp@users.sourceforge.net> | 2011-05-02 15:38:31 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2011-05-02 15:38:31 (GMT) |
commit | caea13f2776c1d71043747539553c566d4186553 (patch) | |
tree | 157fb830c0521a0dfee6f61d29b92b1153f3c44b /generic/tclListObj.c | |
parent | 92906a53a74eaca4671e76dcf8789db8c565c082 (diff) | |
download | tcl-caea13f2776c1d71043747539553c566d4186553.zip tcl-caea13f2776c1d71043747539553c566d4186553.tar.gz tcl-caea13f2776c1d71043747539553c566d4186553.tar.bz2 |
Replace TclCountSpaceRuns() with TclMaxListLength() which is the function we
actually want.
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 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++) { |