Skip to content

Commit

Permalink
filterx/filterx-scope: don't move the variables array multiple times
Browse files Browse the repository at this point in the history
Optimize the removal of multiple elements.

Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Dec 30, 2024
1 parent 7c7ef1f commit 3f96d79
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/filterx/filterx-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,20 @@ filterx_scope_invalidate_log_msg_cache(FilterXScope *self)
{
g_assert(filterx_scope_has_log_msg_changes(self));

gint i = 0;
while (i < self->variables->len)
for (gint src_index = 0, dst_index = 0; src_index < self->variables->len; src_index++)
{
FilterXVariable *v = &g_array_index(self->variables, FilterXVariable, i);
FilterXVariable *v = &g_array_index(self->variables, FilterXVariable, src_index);

if (!filterx_variable_is_floating(v) && self->syncable)
g_array_remove_index(self->variables, i);
{
;
}
else
i++;
{
if (src_index != dst_index)
g_array_index(self->variables, FilterXVariable, dst_index) = g_array_index(self->variables, FilterXVariable, src_index);
dst_index++;
}
}

filterx_scope_clear_log_msg_has_changes(self);
Expand Down

0 comments on commit 3f96d79

Please sign in to comment.