]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: recursion to loop
authorJan Maria Matejka <mq@ucw.cz>
Wed, 29 Nov 2017 10:38:01 +0000 (11:38 +0100)
committerJan Maria Matejka <mq@ucw.cz>
Tue, 13 Mar 2018 15:29:33 +0000 (16:29 +0100)
It was supposed to do tail-recursion in interpret() but it didn't
compile as such. Converting it to loop makes a significant filter
performance improvement for flat filters.

filter/filter.c

index db90941f1c95e54b43126fa5dee289eebcc7d072..85721dbdc011254a9419ff96316d10a655b19ed0 100644 (file)
@@ -633,15 +633,13 @@ static struct f_val
 interpret(struct f_inst *what)
 {
   struct symbol *sym;
-  struct f_val v1, v2, res, *vp;
+  struct f_val v1, v2, res = { .type = T_VOID }, *vp;
   unsigned u1, u2;
   int i;
   u32 as;
 
+  for ( ; what; what = what->next) {
   res.type = T_VOID;
-  if (!what)
-    return res;
-
   switch(what->fi_code) {
   case FI_COMMA:
     TWOARGS;
@@ -1510,9 +1508,7 @@ interpret(struct f_inst *what)
 
   default:
     bug( "Unknown instruction %d (%c)", what->fi_code, what->fi_code & 0xff);
-  }
-  if (what->next)
-    return interpret(what->next);
+  }}
   return res;
 }