diff options
author | dgp <dgp@users.sourceforge.net> | 2007-02-24 18:55:42 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2007-02-24 18:55:42 (GMT) |
commit | f3533a9258ecec84b776d21653f7d91abdf67831 (patch) | |
tree | f723d3e8039a85dd9ef7a2b6fb219fc521969795 /generic/tclListObj.c | |
parent | 3ca3d6597115aa1983bd3504e95769eadba4a594 (diff) | |
download | tcl-f3533a9258ecec84b776d21653f7d91abdf67831.zip tcl-f3533a9258ecec84b776d21653f7d91abdf67831.tar.gz tcl-f3533a9258ecec84b776d21653f7d91abdf67831.tar.bz2 |
* generic/tclBasic.c: Use new interface in Tcl_EvalObjEx so that
the recounting logic of the List internal rep need not be repeated
there. Better encapsulation of internal details.
* generic/tclInt.h: New internal routine TclListObjCopy() used
* generic/tclListObj.c: to efficiently do the equivalent of
[lrange $list 0 end]. After some experience with this, might be
a good candidate for exposure as a public interface. It's useful
for callers of Tcl_ListObjGetElements() who want to control the
ongoing validity of the returned objv pointer.
Diffstat (limited to 'generic/tclListObj.c')
-rw-r--r-- | generic/tclListObj.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 9f15cd2..35db836 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclListObj.c,v 1.34 2006/11/08 13:47:07 dkf Exp $ + * RCS: @(#) $Id: tclListObj.c,v 1.35 2007/02/24 18:55:43 dgp Exp $ */ #include "tclInt.h" @@ -345,6 +345,46 @@ Tcl_SetListObj( /* *---------------------------------------------------------------------- * + * TclListObjCopy -- + * + * Makes a "pure list" copy of a list value. This provides for the + * C level a counterpart of the [lrange $list 0 end] command, while + * using internals details to be as efficient as possible. + * + * Results: + * Normally returns a pointer to a new Tcl_Obj, that contains the + * same list value as *listPtr does. The returned Tcl_Obj has + * a refCount of zero. If *listPtr does not hold a list, NULL + * is returned, and if interp is non-NULL, an error message is + * recorded there. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +Tcl_Obj * +TclListObjCopy( + Tcl_Interp *interp, /* Used to report errors if not NULL. */ + Tcl_Obj *listPtr) /* List object for which an element array is + * to be returned. */ +{ + Tcl_Obj *copyPtr; + if (listPtr->typePtr != &tclListType) { + if (SetListFromAny(interp, listPtr) != TCL_OK) { + return NULL; + } + } + TclNewObj(copyPtr); + TclInvalidateStringRep(copyPtr); + DupListInternalRep(listPtr, copyPtr); + return copyPtr; +} + +/* + *---------------------------------------------------------------------- + * * Tcl_ListObjGetElements -- * * This function returns an (objc,objv) array of the elements in a list |