@@ -284,7 +284,7 @@ filterx_scope_new(void)
284
284
285
285
g_atomic_counter_set (& self -> ref_cnt , 1 );
286
286
self -> variables = g_array_sized_new (FALSE, TRUE, sizeof (FilterXVariable ), 16 );
287
- g_array_set_clear_func (self -> variables , (GDestroyNotify ) filterx_variable_free_method );
287
+ g_array_set_clear_func (self -> variables , (GDestroyNotify ) filterx_variable_free );
288
288
return self ;
289
289
}
290
290
@@ -377,16 +377,31 @@ filterx_scope_invalidate_log_msg_cache(FilterXScope *self)
377
377
{
378
378
g_assert (filterx_scope_has_log_msg_changes (self ));
379
379
380
- gint i = 0 ;
381
- while (i < self -> variables -> len )
380
+ /* this is a bit hacky and the solution would be to get rid of the GArray
381
+ * wrapper. GArray does not allow us to remove multiple elements in a
382
+ * single loop, without moving the array multiple times. So we basically
383
+ * open code this instead of multiple calls to g_array_remove_index()
384
+ */
385
+
386
+ gint src_index , dst_index ;
387
+ for (src_index = 0 , dst_index = 0 ; src_index < self -> variables -> len ; src_index ++ )
382
388
{
383
- FilterXVariable * v = & g_array_index (self -> variables , FilterXVariable , i );
389
+ FilterXVariable * v = & g_array_index (self -> variables , FilterXVariable , src_index );
384
390
385
391
if (!filterx_variable_is_floating (v ) && self -> syncable )
386
- g_array_remove_index (self -> variables , i );
392
+ {
393
+ /* skip this variable */
394
+ filterx_variable_free (v );
395
+ }
387
396
else
388
- i ++ ;
397
+ {
398
+ if (src_index != dst_index )
399
+ g_array_index (self -> variables , FilterXVariable , dst_index ) = g_array_index (self -> variables , FilterXVariable , src_index );
400
+ dst_index ++ ;
401
+ }
389
402
}
403
+ /* and this is the HACK: we reset the "len" member by poking that inside the GArray data structure */
404
+ self -> variables -> len = dst_index ;
390
405
391
406
filterx_scope_clear_log_msg_has_changes (self );
392
407
}
0 commit comments