Skip to content

Commit

Permalink
Merge branch 'lessloop' of github.com:transceptor-technology/libcleri
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Jan 7, 2022
2 parents a753e73 + 99b93eb commit 5b682c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion inc/cleri/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct cleri_rule_tested_s
{
const char * str;
cleri_node_t * node;
cleri_rule_tested_t * prev;
cleri_rule_tested_t * next;
};

struct cleri_rule_store_s
Expand Down
31 changes: 17 additions & 14 deletions src/rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,19 @@ cleri_rule_test_t cleri__rule_init(
return CLERI_RULE_TRUE;
}

do
if ((*target)->str == str)
{
return CLERI_RULE_FALSE;
}

while (((*target) = (*target)->next) != NULL && str <= (*target)->str)
{
if ((*target)->str == str)
{
return CLERI_RULE_FALSE;
}
(*target) = (*target)->prev;
tested = (*target);
}
while ((*target) != NULL);

*target = cleri__malloc(cleri_rule_tested_t);

Expand All @@ -91,9 +95,8 @@ cleri_rule_test_t cleri__rule_init(

(*target)->str = str;
(*target)->node = NULL;
(*target)->prev = tested->prev;
tested->prev = *target;

(*target)->next = tested->next;
tested->next = *target;
return CLERI_RULE_TRUE;
}

Expand Down Expand Up @@ -121,7 +124,7 @@ static cleri_node_t * rule__parse(
nrule.depth = 0;
nrule.tested.str = NULL;
nrule.tested.node = NULL;
nrule.tested.prev = NULL;
nrule.tested.next = NULL;
nrule.root_obj = cl_obj->via.rule->cl_obj;

node = cleri__parse_walk(
Expand Down Expand Up @@ -151,7 +154,7 @@ static cleri_node_t * rule__parse(
nrule.depth = 0;
nrule.tested.str = NULL;
nrule.tested.node = NULL;
nrule.tested.prev = NULL;
nrule.tested.next = NULL;
nrule.root_obj = cl_obj->via.rule->cl_obj;

rnode = cleri__parse_walk(
Expand Down Expand Up @@ -183,14 +186,14 @@ static cleri_node_t * rule__parse(
*/
static void rule__tested_free(cleri_rule_tested_t * tested)
{
cleri_rule_tested_t * prev = tested->prev;
cleri_rule_tested_t * next = tested->next;
cleri__node_free(tested->node);
while (prev != NULL)
while (next != NULL)
{
tested = prev->prev;
cleri__node_free(prev->node);
free(prev);
prev = tested;
tested = next->next;
cleri__node_free(next->node);
free(next);
next = tested;
}
}

2 changes: 1 addition & 1 deletion test/test_thingsdb_lang/test_thingsdb_lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int test_thingsdb_lang(void)
char buf[262144];
char * str = buf;
size_t query_len = strlen(query);
for (i = 0; i < 200; i++)
for (i = 0; i < 20; i++) // max 200
{
memcpy(str, query, query_len);
str += query_len;
Expand Down

0 comments on commit 5b682c2

Please sign in to comment.