#4061 list from dict or "array get" loses internal representations

obsolete: 8.5.3

Accessing a dict Tcl_Obj as a list loses the internal representations of all of the element Tcl_Objs. This is because the list object is rebuilt in SetListFromAny from the dict string representation.

In Tcl 8.5 "array get" has been modified to return a dict object. A consequence of this is that the following code now loses all of the internal representations of the aname and avalue elements.

# Process all array elements.

foreach {aname avalue} [array get arrayVariable] {
# Do something with $aname & $avalue.

This is a very common idiom (at least in my code!), and corresponds to examples on the array man page and in various Tcl books. So we have something of a performance regression from Tcl 8.4.

The problem can be avoided by modifying all such usage to "dict for". However, that is rather obscure, particularly as the array man page only talks about lists and not dicts. I think that it would be good if SetListFromAny could recognise and process a dict object in such a way as to preserve the element Tcl_Objs.


  • Don Porter

    Don Porter - 2008-07-10

    Logged In: YES
    Originator: NO

    Looks like a duplicate of 2008248 ?

  • Don Porter

    Don Porter - 2008-07-10
    • assigned_to: dkf --> dgp
    • status: open --> pending-duplicate
  • Colin McDonald

    Colin McDonald - 2008-07-11

    Logged In: YES
    Originator: YES

    Yes, it is a duplicate of 2008248. For some reason the sourceforge search won't work on my corporate pc/browser at work, which may be why I missed that one.

  • Colin McDonald

    Colin McDonald - 2008-07-11
    • status: pending-duplicate --> closed-duplicate