]> www.infradead.org Git - users/hch/configfs.git/commitdiff
kconfig: cache expression values
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 8 Sep 2024 12:43:21 +0000 (21:43 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Fri, 20 Sep 2024 00:21:53 +0000 (09:21 +0900)
Cache expression values to avoid recalculating them repeatedly.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/confdata.c
scripts/kconfig/expr.c
scripts/kconfig/expr.h
scripts/kconfig/internal.h
scripts/kconfig/symbol.c

index d8849dfb06dbbfc4f5d2757b213bad11cf1d8f3d..4286d5e7f95dc14057d550049f047a099ca21535 100644 (file)
@@ -396,6 +396,8 @@ load:
                }
        }
 
+       expr_invalidate_all();
+
        while (getline_stripped(&line, &line_asize, in) != -1) {
                struct menu *choice;
 
index 476dcaa9078ebbb95f86f7cd0062c3a9540b62c9..78738ef412de2e42ac82eb0718462c2ea7f2e853 100644 (file)
@@ -887,7 +887,7 @@ static enum string_value_kind expr_parse_string(const char *str,
               ? kind : k_string;
 }
 
-tristate expr_calc_value(struct expr *e)
+static tristate __expr_calc_value(struct expr *e)
 {
        tristate val1, val2;
        const char *str1, *str2;
@@ -895,9 +895,6 @@ tristate expr_calc_value(struct expr *e)
        union string_value lval = {}, rval = {};
        int res;
 
-       if (!e)
-               return yes;
-
        switch (e->type) {
        case E_SYMBOL:
                sym_calc_value(e->left.sym);
@@ -961,6 +958,35 @@ tristate expr_calc_value(struct expr *e)
        }
 }
 
+/**
+ * expr_calc_value - return the tristate value of the given expression
+ * @e: expression
+ * return: tristate value of the expression
+ */
+tristate expr_calc_value(struct expr *e)
+{
+       if (!e)
+               return yes;
+
+       if (!e->val_is_valid) {
+               e->val = __expr_calc_value(e);
+               e->val_is_valid = true;
+       }
+
+       return e->val;
+}
+
+/**
+ * expr_invalidate_all - invalidate all cached expression values
+ */
+void expr_invalidate_all(void)
+{
+       struct expr *e;
+
+       hash_for_each(expr_hashtable, e, node)
+               e->val_is_valid = false;
+}
+
 static int expr_compare_type(enum expr_type t1, enum expr_type t2)
 {
        if (t1 == t2)
index a398b2b2dbe053e417535605299a3b9405a92e98..21578dcd4292407ea7280766151db6297c9f8658 100644 (file)
@@ -39,12 +39,16 @@ union expr_data {
  *
  * @node:  link node for the hash table
  * @type:  expressoin type
+ * @val: calculated tristate value
+ * @val_is_valid: indicate whether the value is valid
  * @left:  left node
  * @right: right node
  */
 struct expr {
        struct hlist_node node;
        enum expr_type type;
+       tristate val;
+       bool val_is_valid;
        union expr_data left, right;
 };
 
index 84c2ea0389fdcfec7aa16cbc27ab6b4218b56e7b..d0ffce2dfbba3800973b5f3b4bf56b87e596aa86 100644 (file)
@@ -15,6 +15,8 @@ extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE);
 
 extern HASHTABLE_DECLARE(expr_hashtable, EXPR_HASHSIZE);
 
+void expr_invalidate_all(void);
+
 struct menu;
 
 extern struct menu *current_menu, *current_entry;
index 6243f0143ecf5bd0d1c7519d065e83d0968edb33..a3af93aaaf32af1e1a1a62433888303b30bd7182 100644 (file)
@@ -519,6 +519,7 @@ void sym_clear_all_valid(void)
 
        for_all_symbols(sym)
                sym->flags &= ~SYMBOL_VALID;
+       expr_invalidate_all();
        conf_set_changed(true);
        sym_calc_value(modules_sym);
 }