Skip to content

Commit 95573ca

Browse files
committed
kconfig: cache expression values
Cache expression values to avoid recalculating them repeatedly. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent f93d6bf commit 95573ca

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

scripts/kconfig/confdata.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ int conf_read_simple(const char *name, int def)
396396
}
397397
}
398398

399+
expr_invalidate_all();
400+
399401
while (getline_stripped(&line, &line_asize, in) != -1) {
400402
struct menu *choice;
401403

scripts/kconfig/expr.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,17 +887,14 @@ static enum string_value_kind expr_parse_string(const char *str,
887887
? kind : k_string;
888888
}
889889

890-
tristate expr_calc_value(struct expr *e)
890+
static tristate __expr_calc_value(struct expr *e)
891891
{
892892
tristate val1, val2;
893893
const char *str1, *str2;
894894
enum string_value_kind k1 = k_string, k2 = k_string;
895895
union string_value lval = {}, rval = {};
896896
int res;
897897

898-
if (!e)
899-
return yes;
900-
901898
switch (e->type) {
902899
case E_SYMBOL:
903900
sym_calc_value(e->left.sym);
@@ -961,6 +958,35 @@ tristate expr_calc_value(struct expr *e)
961958
}
962959
}
963960

961+
/**
962+
* expr_calc_value - return the tristate value of the given expression
963+
* @e: expression
964+
* return: tristate value of the expression
965+
*/
966+
tristate expr_calc_value(struct expr *e)
967+
{
968+
if (!e)
969+
return yes;
970+
971+
if (!e->val_is_valid) {
972+
e->val = __expr_calc_value(e);
973+
e->val_is_valid = true;
974+
}
975+
976+
return e->val;
977+
}
978+
979+
/**
980+
* expr_invalidate_all - invalidate all cached expression values
981+
*/
982+
void expr_invalidate_all(void)
983+
{
984+
struct expr *e;
985+
986+
hash_for_each(expr_hashtable, e, node)
987+
e->val_is_valid = false;
988+
}
989+
964990
static int expr_compare_type(enum expr_type t1, enum expr_type t2)
965991
{
966992
if (t1 == t2)

scripts/kconfig/expr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ union expr_data {
3939
*
4040
* @node: link node for the hash table
4141
* @type: expressoin type
42+
* @val: calculated tristate value
43+
* @val_is_valid: indicate whether the value is valid
4244
* @left: left node
4345
* @right: right node
4446
*/
4547
struct expr {
4648
struct hlist_node node;
4749
enum expr_type type;
50+
tristate val;
51+
bool val_is_valid;
4852
union expr_data left, right;
4953
};
5054

scripts/kconfig/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE);
1515

1616
extern HASHTABLE_DECLARE(expr_hashtable, EXPR_HASHSIZE);
1717

18+
void expr_invalidate_all(void);
19+
1820
struct menu;
1921

2022
extern struct menu *current_menu, *current_entry;

scripts/kconfig/symbol.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ void sym_clear_all_valid(void)
519519

520520
for_all_symbols(sym)
521521
sym->flags &= ~SYMBOL_VALID;
522+
expr_invalidate_all();
522523
conf_set_changed(true);
523524
sym_calc_value(modules_sym);
524525
}

0 commit comments

Comments
 (0)