Skip to content

Commit

Permalink
conf: avoid quadratic complexity
Browse files Browse the repository at this point in the history
Ticket: 6878

Follow up on 1564942

When adding many sequence nodes, either from start or scalar event

We add "sequence nodes" whose name is an integer cf sequence_node_name
and then run ConfNodeLookupChild to see if it had been already set
(from the command line cf comment in the code)
And ConfNodeLookupChild iterates the whole linked list...

1. We add node 1
2. To add node 2, we check if node 1 equals this new node
3. To add node 3, we check if nodes 1, or 2 equals this new node's name
And so on...

This commits avoids these checks ig the list is empty at the beginning

(cherry picked from commit 240e068)
  • Loading branch information
catenacyber committed Apr 17, 2024
1 parent 3422764 commit 77563fd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/conf-yaml-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,19 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq, int rlevel)
if (inseq) {
char sequence_node_name[DEFAULT_NAME_LEN];
snprintf(sequence_node_name, DEFAULT_NAME_LEN, "%d", seq_idx++);
ConfNode *seq_node = ConfNodeLookupChild(node,
sequence_node_name);
ConfNode *seq_node = NULL;
if (was_empty < 0) {
// initialize was_empty
if (TAILQ_EMPTY(&node->head)) {
was_empty = 1;
} else {
was_empty = 0;
}
}
// we only check if the node's list was not empty at first
if (was_empty == 0) {
seq_node = ConfNodeLookupChild(node, sequence_node_name);
}
if (seq_node != NULL) {
/* The sequence node has already been set, probably
* from the command line. Remove it so it gets
Expand Down

0 comments on commit 77563fd

Please sign in to comment.