Skip to content

Commit aeac690

Browse files
committed
filterx/expr-compound: add support for inline allocation of pointers
Signed-off-by: Balazs Scheidler <[email protected]>
1 parent 84b6057 commit aeac690

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/filterx/expr-compound.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535
typedef struct _FilterXCompoundExpr
3636
{
3737
FilterXExpr super;
38-
FilterXExprList exprs;
3938
/* whether this is a statement expression */
4039
gboolean return_value_of_last_expr;
40+
41+
/* needs to come last, as this may inline the list of expressions into an
42+
* array piggybacked at the end of this struct */
43+
FilterXExprList exprs;
4144
} FilterXCompoundExpr;
4245

4346
static gboolean
@@ -180,7 +183,19 @@ _optimize(FilterXExpr *s)
180183
FilterXCompoundExpr *self = (FilterXCompoundExpr *) s;
181184

182185
filterx_expr_list_foreach_ref(&self->exprs, _optimize_expr, NULL);
183-
return NULL;
186+
187+
/* reallocate self so we can store the list of expressions inline */
188+
gsize new_size = FILTERX_POINTER_LIST_ALLOC_SIZE(self, exprs);
189+
FilterXCompoundExpr *optimized = (FilterXCompoundExpr *) g_malloc(new_size);
190+
191+
memcpy(optimized, self, sizeof(*self));
192+
optimized->super.ref_cnt = 1;
193+
optimized->super.lloc = NULL;
194+
optimized->super.expr_text = NULL;
195+
filterx_expr_set_location_with_text(&optimized->super, s->lloc, s->expr_text);
196+
197+
filterx_pointer_list_seal_inline(&optimized->exprs, &self->exprs);
198+
return &optimized->super;
184199
}
185200

186201
static gboolean

lib/filterx/expr-literal-container.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct FilterXLiteralElement_
3434
{
3535
FilterXExpr *key;
3636
FilterXExpr *value;
37-
gboolean literal;
3837
};
3938

4039
static gboolean
@@ -57,7 +56,6 @@ _literal_element_optimize(FilterXLiteralElement *self)
5756
{
5857
self->key = filterx_expr_optimize(self->key);
5958
self->value = filterx_expr_optimize(self->value);
60-
self->literal = filterx_expr_is_literal(self->key) && filterx_expr_is_literal(self->value);
6159
}
6260

6361
static void
@@ -178,7 +176,7 @@ _literal_container_optimize(FilterXExpr *s)
178176
FilterXLiteralElement *elem = (FilterXLiteralElement *) filterx_pointer_list_index(&self->elements, i);
179177

180178
_literal_element_optimize(elem);
181-
if (!elem->literal)
179+
if (!filterx_expr_is_literal(elem->key) || !filterx_expr_is_literal(elem->value))
182180
literal = FALSE;
183181
}
184182
if (literal)

0 commit comments

Comments
 (0)