Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-07-11
16:00 • Closed ticket [2014921fff]: list from dict or "array get" loses intern... artifact: 4de624ba7e user: cjmcdonald
00:01 • Pending ticket [2014921fff]. artifact: 063d204e7c user: dgp
2008-07-10
10:56 • New ticket [2014921fff]. artifact: c02aaae0b6 user: cjmcdonald

list from dict or "array get" loses internal representations

Closed / Duplicate2014921fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-07-10 10:56:37
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.
dgpplain2008-07-11 00:01:26
Logged In: YES 
user_id=80530
Originator: NO


Looks like a duplicate of 2008248 ?
cjmcdonaldplain2008-07-11 16:00:34
Logged In: YES 
user_id=883691
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.
Log in (anonymous is fine) to add a comment.