Skip to content

Commit

Permalink
filterx: optimize null coalesce operator for literal operands
Browse files Browse the repository at this point in the history
Signed-off-by: László Várady <laszlo.varady@anno.io>
  • Loading branch information
MrAnno committed Nov 23, 2024
1 parent 20d40a2 commit 7afc4fd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/filterx/expr-null-coalesce.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "filterx/expr-null-coalesce.h"
#include "filterx/expr-literal.h"
#include "filterx/object-null.h"
#include "filterx/filterx-eval.h"
#include "filterx/object-message-value.h"
Expand Down Expand Up @@ -61,6 +62,19 @@ _eval(FilterXExpr *s)
FilterXExpr *
filterx_null_coalesce_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
if (filterx_expr_is_literal(lhs))
{
FilterXObject *lhs_object = filterx_expr_eval(lhs);
if (!lhs_object || filterx_object_is_type(lhs_object, &FILTERX_TYPE_NAME(null)))
{
filterx_object_unref(lhs_object);
return rhs;
}

filterx_object_unref(lhs_object);
return lhs;
}

FilterXNullCoalesce *self = g_new0(FilterXNullCoalesce, 1);
filterx_binary_op_init_instance(&self->super, lhs, rhs);
self->super.super.eval = _eval;
Expand Down

0 comments on commit 7afc4fd

Please sign in to comment.