diff options
author | dgp <dgp@users.sourceforge.net> | 2011-04-18 18:50:41 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2011-04-18 18:50:41 (GMT) |
commit | 66a254dddfb0c618ee609c6bfab4a6549e098772 (patch) | |
tree | 8d78f56622c7353be617d046b3586a18a8ca4ae1 | |
parent | 76259f2d58dc67f1a0095a1891696b69167c3902 (diff) | |
parent | 50920cb27bda1113bd1e4edf637f4a6d03c8d63a (diff) | |
download | tcl-66a254dddfb0c618ee609c6bfab4a6549e098772.zip tcl-66a254dddfb0c618ee609c6bfab4a6549e098772.tar.gz tcl-66a254dddfb0c618ee609c6bfab4a6549e098772.tar.bz2 |
Define and use macros that test whether a Tcl list value is canonical.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | generic/tclBasic.c | 8 | ||||
-rw-r--r-- | generic/tclInt.h | 6 | ||||
-rw-r--r-- | generic/tclUtil.c | 17 |
4 files changed, 20 insertions, 17 deletions
@@ -1,3 +1,9 @@ +2011-04-18 Don Porter <dgp@users.sourceforge.net> + + * generic/tclInt.h: Define and use macros that test whether + * generic/tclBasic.c: a Tcl list value is canonical. + * generic/tclUtil.c: + 2011-04-18 Donal K. Fellows <dkf@users.sf.net> * doc/dict.n: [Bug 3288696]: Command summary was confusingly wrong diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 4c826f3..2da455b 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -5717,8 +5717,7 @@ TclArgumentGet( * up by the caller. It knows better than us. */ - if ((!obj->bytes) || ((obj->typePtr == &tclListType) && - ((List *) obj->internalRep.twoPtrValue.ptr1)->canonicalFlag)) { + if ((obj->bytes == NULL) || TclListObjIsCanonical(obj)) { return; } @@ -5897,7 +5896,6 @@ TclNREvalObjEx( { Interp *iPtr = (Interp *) interp; int result; - List *listRepPtr = objPtr->internalRep.twoPtrValue.ptr1; /* * This function consists of three independent blocks for: direct @@ -5905,9 +5903,7 @@ TclNREvalObjEx( * finally direct evaluation. Precisely one of these blocks will be run. */ - if ((objPtr->typePtr == &tclListType) && /* is a list */ - ((objPtr->bytes == NULL || /* no string rep */ - listRepPtr->canonicalFlag))) { /* or is canonical */ + if (TclListObjIsCanonical(objPtr)) { Tcl_Obj *listPtr = objPtr; CmdFrame *eoFramePtr = NULL; int objc; diff --git a/generic/tclInt.h b/generic/tclInt.h index 29a9316..cf32e0d 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2455,6 +2455,9 @@ typedef struct List { #define ListObjLength(listPtr, len) \ ((len) = ListRepPtr(listPtr)->elemCount) +#define ListObjIsCanonical(listPtr) \ + (((listPtr)->bytes == NULL) || ListRepPtr(listPtr)->canonicalFlag) + #define TclListObjGetElements(interp, listPtr, objcPtr, objvPtr) \ (((listPtr)->typePtr == &tclListType) \ ? ((ListObjGetElements((listPtr), *(objcPtr), *(objvPtr))), TCL_OK)\ @@ -2465,6 +2468,9 @@ typedef struct List { ? ((ListObjLength((listPtr), *(lenPtr))), TCL_OK)\ : Tcl_ListObjLength((interp), (listPtr), (lenPtr))) +#define TclListObjIsCanonical(listPtr) \ + (((listPtr)->typePtr == &tclListType) ? ListObjIsCanonical((listPtr)) : 0) + /* * Macros providing a faster path to integers: Tcl_GetLongFromObj everywhere, * Tcl_GetIntFromObj and TclGetIntForIndex on platforms where longs are ints. diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 4fe1015..f77320b 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1204,19 +1204,14 @@ Tcl_ConcatObj( */ for (i = 0; i < objc; i++) { - List *listRepPtr; + int length; objPtr = objv[i]; - if (objPtr->typePtr != &tclListType) { - TclGetString(objPtr); - if (objPtr->length) { - break; - } else { - continue; - } + if (TclListObjIsCanonical(objPtr)) { + continue; } - listRepPtr = objPtr->internalRep.twoPtrValue.ptr1; - if (objPtr->bytes != NULL && !listRepPtr->canonicalFlag) { + Tcl_GetStringFromObj(objPtr, &length); + if (length > 0) { break; } } @@ -1236,7 +1231,7 @@ Tcl_ConcatObj( */ objPtr = objv[i]; - if (objPtr->bytes && !objPtr->length) { + if (objPtr->bytes && objPtr->length == 0) { continue; } TclListObjGetElements(NULL, objPtr, &listc, &listv); |