File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 35
35
typedef struct _FilterXCompoundExpr
36
36
{
37
37
FilterXExpr super ;
38
- FilterXExprList exprs ;
39
38
/* whether this is a statement expression */
40
39
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 ;
41
44
} FilterXCompoundExpr ;
42
45
43
46
static gboolean
@@ -180,7 +183,19 @@ _optimize(FilterXExpr *s)
180
183
FilterXCompoundExpr * self = (FilterXCompoundExpr * ) s ;
181
184
182
185
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 ;
184
199
}
185
200
186
201
static gboolean
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ struct FilterXLiteralElement_
34
34
{
35
35
FilterXExpr * key ;
36
36
FilterXExpr * value ;
37
- gboolean literal ;
38
37
};
39
38
40
39
static gboolean
@@ -57,7 +56,6 @@ _literal_element_optimize(FilterXLiteralElement *self)
57
56
{
58
57
self -> key = filterx_expr_optimize (self -> key );
59
58
self -> value = filterx_expr_optimize (self -> value );
60
- self -> literal = filterx_expr_is_literal (self -> key ) && filterx_expr_is_literal (self -> value );
61
59
}
62
60
63
61
static void
@@ -178,7 +176,7 @@ _literal_container_optimize(FilterXExpr *s)
178
176
FilterXLiteralElement * elem = (FilterXLiteralElement * ) filterx_pointer_list_index (& self -> elements , i );
179
177
180
178
_literal_element_optimize (elem );
181
- if (!elem -> literal )
179
+ if (!filterx_expr_is_literal ( elem -> key ) || ! filterx_expr_is_literal ( elem -> value ) )
182
180
literal = FALSE;
183
181
}
184
182
if (literal )
You can’t perform that action at this time.
0 commit comments