summaryrefslogtreecommitdiff
path: root/jim.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2014-01-18 13:27:23 +1000
committerSteve Bennett <steveb@workware.net.au>2014-01-18 13:28:01 +1000
commit5e56e1547ceaa2ce77beac0317f72b9ebc945d0e (patch)
tree455bcc750463c2c5a39eb553e7f402ee41e9e11b /jim.c
parente04991828210b4fee8cb84a334d28c242bd5e274 (diff)
jim.c: fix some dict/list shimmering issues
Only do fast dict->list conversion if there is no string rep When converting list->dict, generate the string rep of a shared list to avoid loss of info when converting to dict. Also add a relevent test to dict.test Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim.c')
-rw-r--r--jim.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/jim.c b/jim.c
index 084d513..f3f43e9 100644
--- a/jim.c
+++ b/jim.c
@@ -6313,11 +6313,11 @@ static int SetListFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
return JIM_OK;
}
- /* Optimise dict -> list for unshared object. Note that this may only save a little time, but
+ /* Optimise dict -> list for object with no string rep. Note that this may only save a little time, but
* it also preserves any source location of the dict elements
* which can be very useful
*/
- if (Jim_IsDict(objPtr) && !Jim_IsShared(objPtr)) {
+ if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
Jim_Obj **listObjPtrPtr;
int len;
int i;
@@ -7020,10 +7020,12 @@ static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
return JIM_OK;
}
- /* Get the string representation. Do this first so we don't
- * change order in case of fast conversion to dict.
- */
- Jim_String(objPtr);
+ if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) {
+ /* A shared list, so get the string representation now to avoid
+ * changing the order in case of fast conversion to dict.
+ */
+ Jim_String(objPtr);
+ }
/* For simplicity, convert a non-list object to a list and then to a dict */
listlen = Jim_ListLength(interp, objPtr);