diff options
author | Masahiro Yamada <masahiroy@kernel.org> | 2024-09-08 21:43:21 +0900 |
---|---|---|
committer | Masahiro Yamada <masahiroy@kernel.org> | 2024-09-20 09:21:53 +0900 |
commit | 95573cac25c6b11f02d599d18e9a1c778706e838 (patch) | |
tree | 3659184dcba1d582b845854d326859fdc9048d64 /scripts/kconfig/expr.c | |
parent | f93d6bfbd2f74d79041c153a59df5336f6e9a14a (diff) |
kconfig: cache expression values
Cache expression values to avoid recalculating them repeatedly.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts/kconfig/expr.c')
-rw-r--r-- | scripts/kconfig/expr.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index 476dcaa9078e..78738ef412de 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -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) |