From df94eecf119611a2fa8de1abb3abe59269be7550 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 19 Apr 2018 01:39:38 +0000 Subject: An [array set] from a dict can only take shortcuts when the dict is "pure", that is, has no string rep. --- generic/tclVar.c | 2 +- tests/var.test | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/generic/tclVar.c b/generic/tclVar.c index e540c49..d4e5339 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -3411,7 +3411,7 @@ TclArraySet( * Install the contents of the dictionary or list into the array. */ - if (arrayElemObj->typePtr == &tclDictType) { + if (arrayElemObj->typePtr == &tclDictType && arrayElemObj->bytes == NULL) { Tcl_Obj *keyPtr, *valuePtr; Tcl_DictSearch search; int done; diff --git a/tests/var.test b/tests/var.test index 30e340e..aadeb34 100644 --- a/tests/var.test +++ b/tests/var.test @@ -761,6 +761,18 @@ test var-17.1 {TclArraySet [Bug 1669489]} -setup { } -cleanup { unset -nocomplain ::a ::elements } -result {} +test var-17.2 {TclArraySet Dict shortcut only on pure value} -setup { + unset -nocomplain a d + set d {p 1 p 2} + dict get $d p + set foo 0 +} -body { + trace add variable a write "[list incr [namespace which -variable foo]];#" + array set a $d + set foo +} -cleanup { + unset -nocomplain a d foo +} -result 2 test var-18.1 {array unset and unset traces: Bug 2939073} -setup { set already 0 -- cgit v0.12