From: Egor Date: Sun, 22 Oct 2023 20:15:18 +0000 (+0300) Subject: map: change f->n->value to f->value X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=569ae9ff121847147e249156d58d36bd2850b426;p=patchyircd.git map: change f->n->value to f->value --- diff --git a/src/irc.c b/src/irc.c index 6d6f64b..d2a3243 100644 --- a/src/irc.c +++ b/src/irc.c @@ -31,7 +31,7 @@ void sendbuf_chan_caps(struct channel *chan, unsigned positive, unsigned negativ struct trie_find *f = NULL; if (trie_findfirst(&f, &chan->members) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; if (!(~cl->caps & positive) && !(cl->caps & negative)) sendbuf(cl); } while (trie_findnext(&f) == 1); @@ -43,7 +43,7 @@ void sendbuf_list_sans_self_caps(struct client_data *client, map_t *ls, int cook struct trie_find *f = NULL; if (trie_findfirst(&f, ls) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; if (client != cl) { if (cookie) { if (cookie != cl->cookie) @@ -66,7 +66,7 @@ int get_cookie() { struct trie_find *f = NULL; if (trie_findfirst(&f, &client_map) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; cl->cookie = 0; } while (trie_findnext(&f) == 1); cookie++; @@ -78,7 +78,7 @@ void sendbuf_visible_caps(struct client_data *client, int positive, int negative struct trie_find *f = NULL; if (trie_findfirst(&f, &client->channels) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; sendbuf_list_sans_self_caps(client, &chan->members, cookie, positive, negative); } while (trie_findnext(&f) == 1); } @@ -368,7 +368,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &client_map) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; if (cl->umode & UMODE_WALLOPS) sendbuf(cl); } while (trie_findnext(&f) == 1); @@ -388,7 +388,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &client_map) == 1) do { - struct client_data *cl2 = f->n->value; + struct client_data *cl2 = f->value; if (cl2->umode & UMODE_OPER) sendbuf(cl2); } while (trie_findnext(&f) == 1); @@ -419,7 +419,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &client->channels) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; channel_part(client, chan, "I fell for a classic prank", NULL); } while(trie_findfirst(&f, &client->channels) == 1); free(f); @@ -491,7 +491,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &client->invites) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; rpl_invitelist(client, chan), sendbuf(client); } while(trie_findnext(&f) == 1); return rpl_endofinvitelist(client), sendbuf(client), 0; @@ -970,7 +970,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &channel_map) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; if (!(chan->dmode & DMODE_SECRET) || map_get(&chan->members, client->key)) rpl_list(client, chan), sendbuf(client); } while(trie_findnext(&f) == 1); @@ -1022,7 +1022,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &chan->members) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; rpl_whoreply(client, cl, chan), sendbuf(client); } while(trie_findnext(&f) == 1); } @@ -1057,7 +1057,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a struct trie_find *f = NULL; if (trie_findfirst(&f, &cl->channels) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; if ((cl->umode & UMODE_INVISIBLE || chan->dmode & DMODE_SECRET) && !map_get(&chan->members, client->key)) continue; rpl_whoischannels(client, cl, chan), sendbuf(client); @@ -1148,7 +1148,7 @@ void sendLUSERS(struct client_data *client) struct trie_find *f = NULL; if (trie_findfirst(&f, &client_map) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; registered++; if (cl->umode & UMODE_INVISIBLE) invisible++; @@ -1222,7 +1222,7 @@ void setNick(struct client_data *client, char* nickname) { struct trie_find *f = NULL; if (trie_findfirst(&f, &client->channels) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; map_unset(&chan->members, client->key, NULL); if (map_set(&chan->members, key, client, NULL) == -1) abort(); @@ -1271,7 +1271,7 @@ void channel_sendnames(struct client_data *client, struct channel *chan) databuf.len = 0; if (trie_findfirst(&f, &chan->members) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; if (rpl_namreply(client, chan, cl)) { sendbuf(client); databuf.len = 0; @@ -1387,7 +1387,7 @@ void channel_kill(struct channel *chan) struct trie_find *f = NULL; if (trie_findfirst(&f, &chan->invitees) == 1) do { - struct client_data *cl = f->n->value; + struct client_data *cl = f->value; map_unset(&cl->invites, chan->key, NULL); } while(trie_findnext(&f) == 1); free(chan->key); diff --git a/src/main.c b/src/main.c index c40f815..1e4ce2a 100644 --- a/src/main.c +++ b/src/main.c @@ -422,7 +422,7 @@ int main(int argc, char *argv[]) { struct trie_find *f = NULL; while (trie_findfirst(&f, &channel_map) == 1) { - struct channel *chan = f->n->value; + struct channel *chan = f->value; channel_kill(chan); } free(f); diff --git a/src/map.h b/src/map.h index b7a5c7c..a6add0c 100644 --- a/src/map.h +++ b/src/map.h @@ -24,7 +24,7 @@ struct map_dynarr { typedef struct map_dynarr map_t; struct trie_find { char *key; - struct { void *value; } *n, _n; + void *value; map_t *_root; int _cap; }; @@ -41,6 +41,7 @@ struct trie_node { typedef struct trie_node *map_t; struct trie_find { struct trie_node *n; + void *value; size_t len; size_t cap; char key[1]; diff --git a/src/map_dynarr.c b/src/map_dynarr.c index 6d92ada..43c5805 100644 --- a/src/map_dynarr.c +++ b/src/map_dynarr.c @@ -89,10 +89,9 @@ static int fill(struct trie_find **pf, int index) } *pf = f = nf; f->key = (char*)&f[1]; - f->n = &f->_n; } memcpy(f->key, f->_root->ptr[index].key, keylen); - f->n->value = f->_root->ptr[index].value; + f->value = f->_root->ptr[index].value; return 1; } int trie_findfirst(struct trie_find **pf, map_t *root) @@ -106,7 +105,6 @@ int trie_findfirst(struct trie_find **pf, map_t *root) return -1; f->key = (char*)&f[1]; f->key[0] = 0; - f->n = &f->_n; f->_cap = 32; *pf = f; } else { diff --git a/src/map_trie.c b/src/map_trie.c index 36ed58c..fbb2012 100644 --- a/src/map_trie.c +++ b/src/map_trie.c @@ -153,6 +153,7 @@ int trie_findnext(struct trie_find **pf) { f->key[f->len++] = f->n->key; if (f->n->value) { // found a value f->key[f->len] = '\0'; + f->value = f->n->value; return 1; } ent = 0; // no value, go to the first child @@ -184,6 +185,7 @@ int trie_findfirst(struct trie_find **pf, map_t *root) { f->n = *root; if (f->n->value) { f->key[f->len] = '\0'; + f->value = f->n->value; return 1; } return trie_findnext(pf); diff --git a/src/net.c b/src/net.c index 27b718e..c240866 100644 --- a/src/net.c +++ b/src/net.c @@ -66,7 +66,7 @@ void killConnection(struct client_data *cl, int byChoice) /* Part all channels */ struct trie_find *f = NULL; while (trie_findfirst(&f, &cl->channels) == 1) { - struct channel *chan = f->n->value; + struct channel *chan = f->value; channel_part(cl, chan, NULL, NULL); } free(f); @@ -76,7 +76,7 @@ void killConnection(struct client_data *cl, int byChoice) struct trie_find *f = NULL; if (trie_findfirst(&f, &cl->invites) == 1) do { - struct channel *chan = f->n->value; + struct channel *chan = f->value; map_unset(&chan->invitees, cl->key, NULL); } while(trie_findnext(&f) == 1); }