]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Dropping empty-type const f_vals, they were copied anyway
authorMaria Matejka <mq@ucw.cz>
Fri, 9 Jun 2023 09:02:05 +0000 (11:02 +0200)
committerMaria Matejka <mq@ucw.cz>
Fri, 9 Jun 2023 11:49:31 +0000 (13:49 +0200)
filter/config.Y
filter/data.c
filter/data.h

index a1e5e9f17fd4bb31213b6ccdf3b063b009800d90..205f2c58c3211ea33acbe640c695a7253a755d39 100644 (file)
@@ -191,30 +191,34 @@ f_new_lc_item(u32 f1, u32 t1, u32 f2, u32 t2, u32 f3, u32 t3)
 }
 
 static inline struct f_inst *
-f_generate_empty(struct f_dynamic_attr dyn)
+f_const_empty(struct f_dynamic_attr dyn)
 {
   struct f_val empty;
 
-  switch (dyn.type & EAF_TYPE_MASK) {
+  switch (dyn.type) {
     case EAF_TYPE_AS_PATH:
-      empty = f_const_empty_path;
-      break;
     case EAF_TYPE_INT_SET:
-      empty = f_const_empty_clist;
-      break;
     case EAF_TYPE_EC_SET:
-      empty = f_const_empty_eclist;
-      break;
     case EAF_TYPE_LC_SET:
-      empty = f_const_empty_lclist;
+      empty = (struct f_val) {
+       .type = dyn.f_type,
+       .val.ad = &null_adata,
+      };
       break;
     default:
       cf_error("Can't empty that attribute");
   }
 
-  return f_new_inst(FI_EA_SET, f_new_inst(FI_CONSTANT, empty), dyn);
+  return f_new_inst(FI_CONSTANT, empty);
 }
 
+#define f_dummy_dynattr(_type, _f_type)        ((struct f_dynamic_attr) { .type = _type, .f_type = _f_type, })
+
+#define f_const_empty_path             f_const_empty(f_dummy_dynattr(EAF_TYPE_AS_PATH, T_PATH))
+#define f_const_empty_clist            f_const_empty(f_dummy_dynattr(EAF_TYPE_INT_SET, T_CLIST))
+#define f_const_empty_eclist           f_const_empty(f_dummy_dynattr(EAF_TYPE_EC_SET, T_ECLIST))
+#define f_const_empty_lclist           f_const_empty(f_dummy_dynattr(EAF_TYPE_LC_SET, T_LCLIST))
+
 /*
  * Remove all new lines and doubled whitespaces
  * and convert all tabulators to spaces
@@ -852,10 +856,10 @@ term:
  | dynamic_attr '.' RESET{ }
 */
 
- | '+' EMPTY '+' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_path); }
- | '-' EMPTY '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_clist); }
- | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_eclist); }
- | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_lclist); }
+ | '+' EMPTY '+' { $$ = f_const_empty_path; }
+ | '-' EMPTY '-' { $$ = f_const_empty_clist; }
+ | '-' '-' EMPTY '-' '-' { $$ = f_const_empty_eclist; }
+ | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_const_empty_lclist; }
  | PREPEND '(' term ',' term ')' { $$ = f_new_inst(FI_PATH_PREPEND, $3, $5); }
  | ADD '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_ADD, $3, $5); }
  | DELETE '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_DEL, $3, $5); }
@@ -975,7 +979,7 @@ cmd:
       $$ = f_new_inst(FI_SWITCH, $2, $4);
    }
 
- | dynamic_attr '.' EMPTY ';' { $$ = f_generate_empty($1); }
+ | dynamic_attr '.' EMPTY ';' { $$ = f_new_inst(FI_EA_SET, f_const_empty($1), $1); }
  | dynamic_attr '.' PREPEND '(' term ')' ';'   { $$ = f_generate_complex( FI_PATH_PREPEND, $1, $5 ); }
  | dynamic_attr '.' ADD '(' term ')' ';'       { $$ = f_generate_complex( FI_CLIST_ADD, $1, $5 ); }
  | dynamic_attr '.' DELETE '(' term ')' ';'    { $$ = f_generate_complex( FI_CLIST_DEL, $1, $5 ); }
index 56d746fde6db418160004cd3e2efb68ebb43bfd6..8bd9459510c582abbd7bb99bde2cc762880ac2cf 100644 (file)
@@ -81,20 +81,7 @@ f_type_element_type(enum f_type t)
 }
 
 const struct f_trie f_const_empty_trie = { .ipv4 = -1, };
-
-const struct f_val f_const_empty_path = {
-  .type = T_PATH,
-  .val.ad = &null_adata,
-}, f_const_empty_clist = {
-  .type = T_CLIST,
-  .val.ad = &null_adata,
-}, f_const_empty_eclist = {
-  .type = T_ECLIST,
-  .val.ad = &null_adata,
-}, f_const_empty_lclist = {
-  .type = T_LCLIST,
-  .val.ad = &null_adata,
-}, f_const_empty_prefix_set = {
+const struct f_val f_const_empty_prefix_set = {
   .type = T_PREFIX_SET,
   .val.ti = &f_const_empty_trie,
 };
index b3767f7bc7d58df3150297923d0551f8cb6f88c1..6ca857de2936f1e473e4035423229f8d19e7d78f 100644 (file)
@@ -314,7 +314,7 @@ undef_value(struct f_val v)
     (v.val.ad == &null_adata);
 }
 
-extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist, f_const_empty_prefix_set;
+extern const struct f_val f_const_empty_prefix_set;
 
 enum filter_return f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres);