Author: Sean Woods <email@example.com> State: Draft Type: Project Vote: Pending Created: 12-Feb-2018 Post-History: Keywords: Tcl,string Tcl-Version: 8.7
This tip proposes the addition of an is dict test to the string ensemble. The command will return true if the value is a valid dict, and false otherwise.
Currently the means to test of a string is a leaf node is to check if the string is a list and it's length is divisible by 2. The problem is that this requires 2 different calls from the interpreter, and generates a dict to list conversion for the most common case (namely that the value is, indeed, a dict.)
This tip proposes a shortcut in C to check to see if the internal representation is already a dict, and provide a shortcut for the most common case.
A new branch has been added to the tcl fossil system tip-501
The crux of the implementation is adding "dict" to the IS ensemble:
case STR_IS_DICT: /* * We ignore the strictness here, since empty strings are always * well-formed lists. */ int dresult, dsize; dresult = Tcl_DictObjSize(NULL, objPtr, &dsize); result = (dresult==TCL_OK) ? 1 : 0; break;