Skip to content

Commit

Permalink
feat: added more restrict
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Nov 26, 2023
1 parent de66231 commit 68c75c9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions mse/card_str_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static int __mse_re_match(char *str, mse_re_t *re)

#define __MSE_HASH_DEFAULT 0

int mse_str_match(char *str, char *substr)
int mse_str_match(char * restrict str, char * restrict substr)
{
if (str == NULL) {
return 0;
Expand Down Expand Up @@ -59,15 +59,15 @@ int mse_str_match(char *str, char *substr)
return 0;
}

int mse_card_oracle_matches(mse_card_t *card, mse_re_t *re)
int mse_card_oracle_matches(mse_card_t * restrict card, mse_re_t *re)
{
if (card->oracle_text == NULL) {
return 0;
}
return __mse_re_match(card->oracle_text, re);
}

int mse_card_name_matches(mse_card_t *card, mse_re_t *re)
int mse_card_name_matches(mse_card_t * restrict card, mse_re_t *re)
{
if (card->name == NULL) {
return 0;
Expand Down Expand Up @@ -104,7 +104,7 @@ typedef struct mse_card_match_worker_data_t {
mse_avl_tree_node_t *root;
} mse_card_match_worker_data_t;

static void __mse_match_card_do_match(mse_avl_tree_node_t *node,
static void __mse_match_card_do_match(mse_avl_tree_node_t * restrict node,
mse_card_match_t *match_data,
mse_card_match_cmp_data_t data)
{
Expand Down Expand Up @@ -159,7 +159,7 @@ static void __mse_match_card_do_match(mse_avl_tree_node_t *node,
}
}

static void __mse_match_card_node(mse_avl_tree_node_t *node,
static void __mse_match_card_node(mse_avl_tree_node_t * restrict node,
mse_card_match_t *match_data,
mse_card_match_cmp_data_t cmp_data)
{
Expand Down Expand Up @@ -200,7 +200,7 @@ static void __mse_match_card_worker(void *data, mse_thread_pool_t *pool)

static int __mse_match_card_worker_enqueue(mse_card_match_t *match_data,
mse_thread_pool_t *pool,
mse_avl_tree_node_t *node,
mse_avl_tree_node_t * restrict node,
int h,
mse_card_match_cmp_data_t data)
{
Expand Down Expand Up @@ -248,7 +248,7 @@ static int __mse_match_card_worker_enqueue(mse_card_match_t *match_data,
}

static int __mse_match_cards(mse_avl_tree_node_t **ret,
mse_avl_tree_node_t *cards_tree,
mse_avl_tree_node_t * restrict cards_tree,
char *str,
int is_regex,
int negate,
Expand Down Expand Up @@ -323,7 +323,7 @@ int mse_matching_card_name(mse_avl_tree_node_t **ret,
return __mse_match_cards(ret, cards_tree, str, is_regex, negate, pool, MSE_MATCH_NAME);
}

char *mse_escape_regex(char *regex)
char *mse_escape_regex(char * restrict regex)
{
size_t len = strlen(regex);
ASSERT(len > 1);
Expand Down
34 changes: 17 additions & 17 deletions mse/card_txt_fields_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int mse_init_card_trie_node(mse_card_trie_node_t **node)
return 1;
}

static void __mse_free_card_trie_node(mse_card_trie_node_t *node)
static void __mse_free_card_trie_node(mse_card_trie_node_t * restrict node)
{
if (node == NULL) {
return;
Expand All @@ -30,12 +30,12 @@ static void __mse_free_card_trie_node(mse_card_trie_node_t *node)
free(node);
}

void mse_free_card_trie_node(mse_card_trie_node_t *node)
void mse_free_card_trie_node(mse_card_trie_node_t * restrict node)
{
__mse_free_card_trie_node(node);
}

static int __mse_card_trie_lookup(mse_card_trie_node_t *root, char *str, mse_avl_tree_node_t **ret, int i)
static int __mse_card_trie_lookup(mse_card_trie_node_t * restrict root, char * restrict str, mse_avl_tree_node_t **ret, int i)
{
if (str[i] == 0) {
// Copy the tree
Expand All @@ -58,7 +58,7 @@ static int __mse_card_trie_lookup(mse_card_trie_node_t *root, char *str, mse_avl
return __mse_card_trie_lookup(root->children[c_index], str, ret, i + 1);
}

int mse_card_trie_lookup(mse_card_trie_node_t *trie, char *str, mse_avl_tree_node_t **ret)
int mse_card_trie_lookup(mse_card_trie_node_t * restrict trie, char * restrict str, mse_avl_tree_node_t **ret)
{
*ret = NULL;
char *str_f = mse_filter_text(str);
Expand All @@ -70,7 +70,7 @@ int mse_card_trie_lookup(mse_card_trie_node_t *trie, char *str, mse_avl_tree_nod
return 1;
}

static int __mse_insert_avl(mse_avl_tree_node_t **root, mse_avl_tree_node_t *node)
static int __mse_insert_avl(mse_avl_tree_node_t **root, mse_avl_tree_node_t * restrict node)
{
if (node == NULL) {
return 1;
Expand All @@ -92,7 +92,7 @@ static int __mse_insert_avl(mse_avl_tree_node_t **root, mse_avl_tree_node_t *nod
return 1;
}

static int __mse_insert_trie_children(mse_card_trie_node_t *node, mse_avl_tree_node_t **ret)
static int __mse_insert_trie_children(mse_card_trie_node_t * restrict node, mse_avl_tree_node_t **ret)
{
if (node == NULL) {
return 1;
Expand All @@ -105,7 +105,7 @@ static int __mse_insert_trie_children(mse_card_trie_node_t *node, mse_avl_tree_n
return 1;
}

static int __mse_card_trie_lookup_aprox(mse_card_trie_node_t *root, char *str, mse_avl_tree_node_t **ret, int i)
static int __mse_card_trie_lookup_aprox(mse_card_trie_node_t * restrict root, char * restrict str, mse_avl_tree_node_t **ret, int i)
{
if (str[i] == 0) {
ASSERT(__mse_insert_trie_children(root, ret));
Expand All @@ -121,7 +121,7 @@ static int __mse_card_trie_lookup_aprox(mse_card_trie_node_t *root, char *str, m
return __mse_card_trie_lookup_aprox(root->children[c_index], str, ret, i + 1);
}

int mse_card_trie_lookup_aprox(mse_card_trie_node_t *trie, char *str, mse_avl_tree_node_t **ret)
int mse_card_trie_lookup_aprox(mse_card_trie_node_t * restrict trie, char * restrict str, mse_avl_tree_node_t **ret)
{
*ret = NULL;
char *str_f = mse_filter_text(str);
Expand All @@ -133,7 +133,7 @@ int mse_card_trie_lookup_aprox(mse_card_trie_node_t *trie, char *str, mse_avl_tr
return 1;
}

static int __mse_card_trie_do_insert(mse_card_trie_node_t *root, mse_card_t *card)
static int __mse_card_trie_do_insert(mse_card_trie_node_t *root, mse_card_t * restrict card)
{
mse_avl_tree_node_t *node = mse_init_avl_tree_node(MSE_CARD_DEFAULT_FREE_FUNCTION,
MSE_CARD_DEFAULT_COMPARE_FUNCTION,
Expand All @@ -145,7 +145,7 @@ static int __mse_card_trie_do_insert(mse_card_trie_node_t *root, mse_card_t *car
return 1;
}

static int __mse_card_trie_insert(mse_card_trie_node_t *root, mse_card_t *card, char *str, int index)
static int __mse_card_trie_insert(mse_card_trie_node_t *root, mse_card_t * restrict card, char * restrict str, int index)
{
if (str[index] == 0) {
return __mse_card_trie_do_insert(root, card);
Expand All @@ -164,7 +164,7 @@ static int __mse_card_trie_insert(mse_card_trie_node_t *root, mse_card_t *card,
return __mse_card_trie_insert(root->children[c_index], card, str, index + 1);
}

int mse_card_trie_insert(mse_card_trie_node_t *root, mse_card_t *card, char *str)
int mse_card_trie_insert(mse_card_trie_node_t *root, mse_card_t * restrict card, char * restrict str)
{
char *str_f = mse_filter_text(str);
ASSERT(str_f != NULL);
Expand All @@ -185,15 +185,15 @@ char __mse_filter_char(char c)
return mse_filter_char_map[i];
}

static int __is_duplicate(char *str, int i, char c)
static int __is_duplicate(char * restrict str, int i, char c)
{
if (i > 0) {
return str[i - 1] == c;
}
return 0;
}

char *mse_filter_text(char *str)
char *mse_filter_text(char * restrict str)
{
size_t len = strlen(str);
char *ret = malloc(len + 1);
Expand Down Expand Up @@ -223,7 +223,7 @@ char *mse_filter_text(char *str)
return ret;
}

static int __mse_insert_to_name_parts(mse_card_name_parts_t *ret, char *fname)
static int __mse_insert_to_name_parts(mse_card_name_parts_t *ret, char * restrict fname)
{
char **tmp = realloc(ret->parts, sizeof(*ret->parts) * (ret->len + 1));
if (tmp == NULL) {
Expand Down Expand Up @@ -253,7 +253,7 @@ static int __mse_is_vowel(char c)
}
}

static int __mse_split_card_name(char *name, mse_card_name_parts_t *ret)
static int __mse_split_card_name(char * restrict name, mse_card_name_parts_t * restrict ret)
{
char *tmp = name;
size_t len = strlen(name);
Expand Down Expand Up @@ -285,7 +285,7 @@ static int __mse_split_card_name(char *name, mse_card_name_parts_t *ret)
return 1;
}

void mse_free_card_parts(mse_card_name_parts_t *ret)
void mse_free_card_parts(mse_card_name_parts_t * restrict ret)
{
if (ret->parts != NULL) {
for (size_t i = 0; i < ret->len; i++) {
Expand All @@ -298,7 +298,7 @@ void mse_free_card_parts(mse_card_name_parts_t *ret)
memset(ret, 0, sizeof(*ret));
}

int mse_split_card_name(char *name, mse_card_name_parts_t *ret)
int mse_split_card_name(char * restrict name, mse_card_name_parts_t * restrict ret)
{
memset(ret, 0, sizeof(*ret));

Expand Down
22 changes: 11 additions & 11 deletions mse/mtg_json_indexes.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct mse_colour_index_generator_state_t {

#define MSE_INDEX_FOR_COLOUR(colour_field, cmp_type) \
static int MSE_INDEX_COLOUR_NAME_IMPL_RECURSIVE(colour_field, cmp_type) \
(mse_avl_tree_node_t *cards, \
(mse_avl_tree_node_t * restrict cards, \
mse_avl_tree_node_t **tree, \
mse_colour_enum_t colours) \
{ \
Expand Down Expand Up @@ -55,7 +55,7 @@ static void MSE_INDEX_COLOUR_NAME_IMPL(colour_field, cmp_type)(void *__state, ms
free(gstate); \
} \
static int MSE_INDEX_COLOUR_NAME_IMPL_THREAD(colour_field, cmp_type) \
(mse_colour_index_generator_state_t gen_state, mse_index_generator_state_t *state) \
(mse_colour_index_generator_state_t gen_state, mse_index_generator_state_t * state) \
{ \
mse_colour_index_generator_state_t *gstate = malloc(sizeof(*gstate)); \
ASSERT(gstate != NULL); \
Expand Down Expand Up @@ -120,7 +120,7 @@ MSE_INDEX_FOR_COLOUR_FIELD(colour_identity)
&MSE_INDEX_COLOUR_NAME(colour_field, eq)

// Set cards index
static int __mse_add_card_to_set(mse_card_t *card, mse_avl_tree_node_t *sets)
static int __mse_add_card_to_set(mse_card_t * restrict card, mse_avl_tree_node_t * restrict sets)
{
for (size_t i = 0; i < card->set_codes_count; i++) {
// Create a proxy element for the tree search as the tree will be comparing mse_set_t objects
Expand All @@ -143,7 +143,7 @@ static int __mse_add_card_to_set(mse_card_t *card, mse_avl_tree_node_t *sets)
return 1;
}

static int __add_cards_to_set(mse_avl_tree_node_t *cards, mse_avl_tree_node_t *sets)
static int __add_cards_to_set(mse_avl_tree_node_t * restrict cards, mse_avl_tree_node_t * restrict sets)
{
if (cards == NULL) {
return 1;
Expand All @@ -164,7 +164,7 @@ static void __mse_generate_set_cards_index_task(void *__state, mse_thread_pool_t
sem_post(&(state->semaphore));
}

static int __insert_node(mse_avl_tree_node_t **root, mse_avl_tree_node_t *node)
static int __insert_node(mse_avl_tree_node_t **root, mse_avl_tree_node_t * restrict node)
{
if (*root == NULL) {
*root = node;
Expand All @@ -176,7 +176,7 @@ static int __insert_node(mse_avl_tree_node_t **root, mse_avl_tree_node_t *node)

#define MSE_INDEX_FIELD_NAME(fname) __mse_generate_card_##fname##_index_task
#define MSE_INDEX_FOR_FIELD(fname) \
static int __add_cards_to_##fname##_tree(mse_avl_tree_node_t *cards, mse_avl_tree_node_t **card_##fname##_tree) \
static int __add_cards_to_##fname##_tree(mse_avl_tree_node_t *restrict cards, mse_avl_tree_node_t **card_##fname##_tree) \
{ \
if (cards == NULL) { \
return 1; \
Expand Down Expand Up @@ -207,7 +207,7 @@ MSE_INDEX_FOR_FIELD(power)
MSE_INDEX_FOR_FIELD(toughness)
MSE_INDEX_FOR_FIELD(cmc)

static int __add_cards_to_card_name_trie(mse_avl_tree_node_t *node, mse_card_trie_node_t *card_name_trie)
static int __add_cards_to_card_name_trie(mse_avl_tree_node_t *restrict node, mse_card_trie_node_t * restrict card_name_trie)
{
if (node == NULL) {
return 1;
Expand All @@ -230,7 +230,7 @@ static void __mse_generate_card_name_trie_task(void *__state, mse_thread_pool_t
sem_post(&(state->semaphore));
}

static int __add_cards_to_card_type_trie(mse_avl_tree_node_t *node, mse_card_trie_node_t *card_type_trie)
static int __add_cards_to_card_type_trie(mse_avl_tree_node_t * restrict node, mse_card_trie_node_t * restrict card_type_trie)
{
if (node == NULL) {
return 1;
Expand All @@ -255,8 +255,8 @@ static void __mse_generate_card_type_trie_task(void *__state, mse_thread_pool_t
sem_post(&(state->semaphore));
}

static int __add_cards_to_card_name_parts_trie(mse_avl_tree_node_t *node,
mse_card_trie_node_t *card_name_parts_trie)
static int __add_cards_to_card_name_parts_trie(mse_avl_tree_node_t * restrict node,
mse_card_trie_node_t * restrict card_name_parts_trie)
{
if (node == NULL) {
return 1;
Expand Down Expand Up @@ -293,7 +293,7 @@ static void __mse_generate_card_name_parts_trie_task(void *__state, mse_thread_p

#define TASK_COUNT(T) (sizeof(T) / sizeof(*T))

int __mse_generate_indexes(mse_all_printings_cards_t *ret, mse_thread_pool_t *pool)
int __mse_generate_indexes(mse_all_printings_cards_t * restrict ret, mse_thread_pool_t *pool)
{
ASSERT(pool != NULL);
ASSERT(ret != NULL);
Expand Down

0 comments on commit 68c75c9

Please sign in to comment.