summaryrefslogtreecommitdiff
path: root/conf/cf-lex.l
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2023-04-27 18:20:49 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2023-04-27 18:41:01 +0200
commita8a64ca0fed41c78376b27880e934296bd3c3a7f (patch)
treeb07dce29bd01d67438438278bc8af89879faba12 /conf/cf-lex.l
parent9b471e72d75c154f3b8c4fa134c7c9f1a55fe27f (diff)
Conf: Improve handling of keywords
For whatever reason, parser allocated a symbol for every parsed keyword in each scope. That wasted time and memory. The effect is worsened with recent changes allowing local scopes, so keywords often promote soft scopes (with no symbols) to real scopes. Do not allocate a symbol for a keyword. Take care of keywords that could be promoted to symbols (kw_sym) and do it explicitly.
Diffstat (limited to 'conf/cf-lex.l')
-rw-r--r--conf/cf-lex.l17
1 files changed, 13 insertions, 4 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index 0a02dd73..9555949d 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -601,6 +601,10 @@ cf_new_symbol(const byte *c)
return s;
}
+struct symbol *
+cf_symbol_from_keyword(const struct keyword *kw)
+{ return cf_new_symbol(kw->name); }
+
/**
* cf_find_local_symbol - find a symbol by name
* @cfg: specificed config
@@ -692,18 +696,23 @@ static enum yytokentype
cf_lex_symbol(const char *data)
{
/* Have we defined such a symbol? */
- struct symbol *sym = cf_get_symbol(data);
- cf_lval.s = sym;
+ struct symbol *sym = cf_find_local_symbol(new_config, conf_this_scope, data);
- if (sym->class != SYM_VOID)
+ if (sym && (sym->class != SYM_VOID))
+ {
+ cf_lval.s = sym;
return CF_SYM_KNOWN;
+ }
/* Is it a keyword? */
struct keyword *k = HASH_FIND(kw_hash, KW, data);
if (k)
{
if (k->value > 0)
+ {
+ cf_lval.kw = k;
return k->value;
+ }
else
{
cf_lval.i = -k->value;
@@ -712,7 +721,7 @@ cf_lex_symbol(const char *data)
}
/* OK, undefined symbol */
- cf_lval.s = sym;
+ cf_lval.s = cf_new_symbol(data);
return CF_SYM_UNDEFINED;
}