Groovy evaluator: fix in workspace variables management
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sat, 25 Apr 2015 12:05:13 +0100
changeset 3441 48320b2d41e6
parent 3440 b2db776bc6dd
child 3442 e59716e00703
Groovy evaluator: fix in workspace variables management When updating workspace variables from Groovy's Binding object, only update those that really changed. This avoids unnecessary unwrap and - more importantly, identity is preserved in case the variable is not touched by the evaluated code.
GroovyEvaluator.st
--- a/GroovyEvaluator.st	Wed Apr 22 11:24:11 2015 +0100
+++ b/GroovyEvaluator.st	Sat Apr 25 12:05:13 2015 +0100
@@ -20,6 +20,8 @@
 "
 "{ Package: 'stx:libjava' }"
 
+"{ NameSpace: Smalltalk }"
+
 Object subclass:#GroovyEvaluator
 	instanceVariableNames:'requestor source'
 	classVariableNames:'WorkspaceShell'
@@ -257,7 +259,11 @@
                 | value |
 
                 value := context getVariable: name.
-                pair second value: (value class javaUnwrap: value).
+                "/ Update variable if it has been changed during
+                "/ evaluation
+                value ~~ pair second value ifTrue:[ 
+                    pair second value: (value class javaUnwrap: value).
+                ].
             ].
         ].
     ] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex|
@@ -267,7 +273,7 @@
     ^ result class javaUnwrap: result.
 
     "Created: / 19-02-2014 / 09:13:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 06-08-2014 / 14:01:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-04-2015 / 11:58:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GroovyEvaluator methodsFor:'error reporting'!