]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more peephole optimizations for logical operations
authorAlan T. DeKok <aland@freeradius.org>
Tue, 5 Sep 2023 17:38:34 +0000 (13:38 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 5 Sep 2023 17:38:55 +0000 (13:38 -0400)
src/lib/unlang/xlat_purify.c
src/tests/unit/condition/base.txt

index 6492b16276e8822151443dacf8fd48e87acb5120..c4b14a40a3f50f89c897b8c519d6a7df95063a33 100644 (file)
@@ -254,7 +254,15 @@ static xlat_exp_t *logical_peephole_optimize(xlat_exp_t *lhs, fr_token_t op, xla
         *      lhs->call.args->flags.can_purify |= rhs->flags.can_purify | rhs->flags.pure;
         *      lhs->flags.can_purify = lhs->call.args->flags.can_purify;
         */
-       if (!is_truthy(lhs, &value)) return NULL;
+       if (!is_truthy(lhs, &value)) {
+               xlat_exp_t *tmp;
+
+               if (!is_truthy(rhs, &value)) return NULL;
+
+               tmp = lhs;
+               lhs = rhs;
+               rhs = tmp;
+       }
 
        /*
         *      1 && FOO   --> FOO
index 1a9e6d0b29d4e6e2841ed6d3eb72b58212057b17..78fbb08637bac001e16ebbf862b873f8d7d26528 100644 (file)
@@ -649,13 +649,11 @@ match false
 #
 #  More short-circuit evaluations
 #
-#  @todo - peephole - optimise at parse time
-#
 condition (&User-Name == "bob") && (false)
-match ((&User-Name == "bob") && false)
+match false
 
 condition (&User-Name == "bob") || (true)
-match ((&User-Name == "bob") || true)
+match true
 
 #
 #  A && (B || C) is not the same as (A && B) || C, for 0/1/1