[anaconda:master 2/2] Memoize the results for *RaidLevelsSupported() functions
Vratislav Podzimek
vpodzime at redhat.com
Thu Jun 5 07:29:11 UTC 2014
On Mon, 2014-06-02 at 16:35 -0400, mulhern wrote:
> 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
This could be used in many other places so it should be defined in some
"more general module" like iutil.py or something like that.
--
Vratislav Podzimek
Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list