]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Performance optimization
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 9 Sep 2014 05:08:57 +0000 (05:08 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 9 Sep 2014 05:08:57 +0000 (05:08 +0000)
refs #5261

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30236 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java

index 0b03a5b4ad08c4cf6f6362940c64175df8ecb902..bf71e39fd2d4e3fd5e4bc5154a52225323e73d90 100644 (file)
@@ -38,6 +38,7 @@ public abstract class IndexVariable<T> extends AbstractPropertyVariable {
        protected HashMap<String, String> rvis;\r
        protected String indexes;\r
        protected VariableSubscriptionManager subscriptionManager;\r
+       protected Pair<ArrayList<String>,ArrayList<String>> variableNameArrays;\r
        \r
        public IndexVariable(ReadGraph graph, Variable parent, String indexes) throws DatabaseException {\r
                this.parent = parent;\r
@@ -164,68 +165,83 @@ public abstract class IndexVariable<T> extends AbstractPropertyVariable {
        }\r
        \r
        protected void ensureInformationAvailable(ReadGraph graph) throws DatabaseException {\r
-               SimulationResource SIMU = SimulationResource.getInstance(graph);\r
-               ModelingResources MOD = ModelingResources.getInstance(graph);\r
                \r
         if(model == null) {\r
+               SimulationResource SIMU = SimulationResource.getInstance(graph);\r
             Resource modelResource = Variables.getModel(graph, parent);\r
             Resource configuration = graph.getPossibleObject(modelResource, SIMU.HasConfiguration);\r
             model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
         }\r
-        \r
-        Variable var = parent.getParent(graph);\r
-        Resource represents = var.getRepresents(graph);\r
-        \r
-        Resource activeRun = null;\r
-        if(represents != null) {\r
-            do {\r
-                if(graph.isInstanceOf(represents, SIMU.Run)) {\r
-                    activeRun = represents;\r
-                    break;\r
-                }\r
-                var = var.getParent(graph);\r
-                represents = var.getRepresents(graph);\r
-            } while(represents != null && !graph.isInstanceOf(represents, MOD.StructuralModel));\r
-        }\r
 \r
-        IProject project = Simantics.peekProject();\r
-        if(activeRun != null && project != null) {\r
-            IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
-               IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, activeRun));\r
-               if(e instanceof SysdynExperiment)\r
-                       this.experiment = (SysdynExperiment)e;\r
+        if(this.experiment == null || this.subscriptionManager == null) {\r
+               SimulationResource SIMU = SimulationResource.getInstance(graph);\r
+               ModelingResources MOD = ModelingResources.getInstance(graph);\r
+               Variable var = parent.getParent(graph);\r
+               Resource represents = var.getRepresents(graph);\r
+               Resource activeRun = null;\r
+               if(represents != null) {\r
+                       do {\r
+                               if(graph.isInstanceOf(represents, SIMU.Run)) {\r
+                                       activeRun = represents;\r
+                                       break;\r
+                               }\r
+                               var = var.getParent(graph);\r
+                               represents = var.getRepresents(graph);\r
+                       } while(represents != null && !graph.isInstanceOf(represents, MOD.StructuralModel));\r
+               }\r
+\r
+               IProject project = Simantics.peekProject();\r
+               if(activeRun != null && project != null) {\r
+                       IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+                       IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, activeRun));\r
+                       if(e instanceof SysdynExperiment)\r
+                               this.experiment = (SysdynExperiment)e;\r
+               }\r
+               this.subscriptionManager = getSubscriptionManager();\r
         }\r
         \r
-        this.subscriptionManager = getSubscriptionManager();\r
-               rvi =  Variables.getPossibleRVI(graph, this);\r
+        if(rvi == null)\r
+               rvi =  Variables.getPossibleRVI(graph, this);\r
+        \r
                if(rvi != null)\r
-                   rvis = graph.syncRequest(new VariableRVIUtils.GetActiveRVIs(parent.getParent(graph))); //VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph));    \r
+                   rvis = graph.syncRequest(new VariableRVIUtils.GetActiveRVIs(parent.getParent(graph))); //VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph));\r
+               \r
        }\r
        \r
        private Pair<ArrayList<String>,ArrayList<String>> getVariableNameArrays() {\r
-               Pair<ArrayList<String>,ArrayList<String>> result = new Pair<ArrayList<String>,ArrayList<String>>(new ArrayList<String>(), new ArrayList<String>());\r
-               if(rvi == null || rvis == null)\r
-                   return result;\r
                \r
-        if(rvi.indexOf('#') > 0)\r
-               rvi = rvi.substring(0, rvi.indexOf('#'));\r
-        \r
-        String test = rvi;\r
-        if(indexes != null && !indexes.isEmpty()) {\r
-               String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012\r
-               test = rvi + "\\[" + regexIndexes + "\\]";\r
-        } else {\r
-               test = rvi + "(\\[.*\\])?";\r
-        }\r
-        for(String k : rvis.keySet()) {\r
-               String value = rvis.get(k);\r
-               if(k.matches(test) || value.matches(test)) {\r
-                       result.first.add(k.substring(1).replace("/", ".").replace("%20", "_"));\r
-                       result.second.add(value.substring(1).replace("/", ".").replace("%20", " "));\r
-               }\r
-        }\r
-        \r
-        return result;\r
+               if(variableNameArrays == null) {\r
+               \r
+                       Pair<ArrayList<String>,ArrayList<String>> result = new Pair<ArrayList<String>,ArrayList<String>>(new ArrayList<String>(), new ArrayList<String>());\r
+                       if(rvi != null && rvis != null) {\r
+                       \r
+                       if(rvi.indexOf('#') > 0)\r
+                               rvi = rvi.substring(0, rvi.indexOf('#'));\r
+                       \r
+                       String test = rvi;\r
+                       if(indexes != null && !indexes.isEmpty()) {\r
+                               String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012\r
+                               test = rvi + "\\[" + regexIndexes + "\\]";\r
+                       } else {\r
+                               test = rvi + "(\\[.*\\])?";\r
+                       }\r
+                       for(String k : rvis.keySet()) {\r
+                               String value = rvis.get(k);\r
+                               if(k.matches(test) || value.matches(test)) {\r
+                                       result.first.add(k.substring(1).replace("/", ".").replace("%20", "_"));\r
+                                       result.second.add(value.substring(1).replace("/", ".").replace("%20", " "));\r
+                               }\r
+                       }\r
+                       \r
+                       variableNameArrays = result;\r
+\r
+                       }\r
+               \r
+               }\r
+               \r
+               if(variableNameArrays == null) return new Pair<ArrayList<String>,ArrayList<String>>(new ArrayList<String>(), new ArrayList<String>());\r
+               \r
+               return variableNameArrays;\r
                \r
        }\r
        \r
index 3d20128c460f332daf274e65d2a95d034da4eb9a..6a79068f19d4ad33a9a347a381212e84820fcbb1 100644 (file)
@@ -127,20 +127,26 @@ public class SysdynConsole implements ISolverMonitor {
         }\r
     }\r
 \r
+    final static private SimpleDateFormat hhmmss = new SimpleDateFormat("hh:mm:ss");\r
+    \r
     @Override\r
     public void message(String message) {\r
-        message(message, "hh:mm:ss");\r
+        message(message, hhmmss);\r
+    }\r
+\r
+    public void message(String message, String timeStampFormat) {\r
+        message(message, new SimpleDateFormat(timeStampFormat));\r
     }\r
 \r
+    final static Calendar cal = Calendar.getInstance();\r
+\r
     /**\r
      * Print message to a console with a specified time stamp format\r
      * \r
      * @param message the message to be printed\r
      * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted\r
      */\r
-    public void message(String message, String timeStampFormat) {\r
-        Calendar cal = Calendar.getInstance();\r
-        SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat);\r
+    public void message(String message, SimpleDateFormat sdf) {\r
         String time = sdf.format(cal.getTime());\r
 \r
         MessageConsoleStream out = this.console.newMessageStream();\r