From 8975bfdb999983c1554d8db65b68d291946a53e1 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 9 Sep 2017 16:11:05 -0700 Subject: [PATCH] Precompute Pi, and do not store documentation on access. --- .../org/nwapw/abacus/plugin/PluginManager.java | 14 ++------------ .../java/org/nwapw/abacus/fx/AbacusController.java | 7 ++++++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java index 3d4f384..27404d4 100644 --- a/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java +++ b/core/src/main/java/org/nwapw/abacus/plugin/PluginManager.java @@ -141,6 +141,7 @@ public class PluginManager { registeredNumberImplementations.put(name, implementation); interfaceImplementationNames.put(implementation.getImplementation(), name); interfaceImplementations.put(implementation.getImplementation(), implementation); + cachedPi.put(implementation.getImplementation(), implementation.instanceForPi()); } /** @@ -218,10 +219,6 @@ public class PluginManager { break; } } - if (toReturn == null) { - toReturn = new Documentation(name, "", "", "", type); - registerDocumentation(toReturn); - } return toReturn; } @@ -252,14 +249,7 @@ public class PluginManager { * @return pi */ public NumberInterface piFor(Class forClass) { - if (cachedPi.containsKey(forClass)) return cachedPi.get(forClass); - NumberImplementation implementation = interfaceImplementationFor(forClass); - NumberInterface generatedPi = null; - if (implementation != null) { - generatedPi = implementation.instanceForPi(); - } - cachedPi.put(forClass, generatedPi); - return generatedPi; + return cachedPi.get(forClass); } /** diff --git a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 5f23a9a..15c75b8 100644 --- a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -363,7 +363,12 @@ public class AbacusController implements PluginListener { enabledPlugins.add(plugin); } PluginManager pluginManager = abacus.getPluginManager(); - functionList.addAll(manager.getAllFunctions().stream().map(name -> pluginManager.documentationFor(name, DocumentationType.FUNCTION)) + functionList.addAll(manager.getAllFunctions().stream().map(name -> { + Documentation documentationInstance = pluginManager.documentationFor(name, DocumentationType.FUNCTION); + if(documentationInstance == null) + documentationInstance = new Documentation(name, "", "", "", DocumentationType.FUNCTION); + return documentationInstance; + }) .collect(Collectors.toCollection(ArrayList::new))); functionList.addAll(manager.getAllTreeValueFunctions().stream().map(name -> pluginManager.documentationFor(name, DocumentationType.TREE_VALUE_FUNCTION)) .collect(Collectors.toCollection(ArrayList::new)));