[anaconda:master 2/2] Memoize the results for *RaidLevelsSupported() functions

mulhern amulhern at redhat.com
Mon Jun 2 20:35:31 UTC 2014


These functions are called repeatedly by the _raid_level_visible functions
to decide whether a particular RAIDLevel option should be shown.
That's a lot of set operations every time when there are so few different
results.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
index d02d49a..ad58517 100644
--- a/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
+++ b/pyanaconda/ui/gui/spokes/lib/custom_storage_helpers.py
@@ -31,6 +31,7 @@ __all__ = ["size_from_entry", "populate_mountpoint_store", "validate_label",
            "AddDialog", "ConfirmDeleteDialog", "DisksDialog", "ContainerDialog",
            "HelpDialog"]
 
+import functools
 import re
 
 from pyanaconda.product import productName
@@ -219,6 +220,20 @@ def requiresRaidSelection(device_type):
     """ Whether GUI requires a RAID level be selected for this device type."""
     return device_type == DEVICE_TYPE_MD
 
+def memoizer(f):
+    @functools.wraps(f)
+    def new_func(arg, cache={}):
+        # pylint: disable=dangerous-default-value
+        if arg in cache:
+            return cache[arg]
+
+        result = f(arg)
+        cache[arg] = result
+        return result
+
+    return new_func
+
+ at memoizer
 def raidLevelsSupported(device_type):
     """ The raid levels anaconda supports for this device type.
 
@@ -241,6 +256,7 @@ def raidLevelsSupported(device_type):
         supported = set()
     return get_supported_raid_levels(device_type).intersection(supported)
 
+ at memoizer
 def containerRaidLevelsSupported(device_type):
     """ The raid levels anaconda supports for a container for this
         device_type.
-- 
1.8.3.1



More information about the anaconda-patches mailing list