mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
parse: move cmd_dict to a std::set
This commit is contained in:
parent
4ed0aebcb6
commit
1c77b054a8
4 changed files with 13 additions and 31 deletions
|
@ -26,6 +26,8 @@
|
|||
#define INCLUDED_parse_h_h
|
||||
|
||||
#include <rb/dictionary.h>
|
||||
#include <ircd/util.h>
|
||||
#include <map>
|
||||
|
||||
struct Message;
|
||||
struct Client;
|
||||
|
@ -34,12 +36,11 @@ struct MsgBuf;
|
|||
extern void parse(struct Client *, char *, char *);
|
||||
extern void handle_encap(struct MsgBuf *, struct Client *, struct Client *,
|
||||
const char *, int, const char *parv[]);
|
||||
extern void clear_hash_parse(void);
|
||||
extern void mod_add_cmd(struct Message *msg);
|
||||
extern void mod_del_cmd(struct Message *msg);
|
||||
extern char *reconstruct_parv(int parc, const char *parv[]);
|
||||
|
||||
extern rb_dictionary *alias_dict;
|
||||
extern rb_dictionary *cmd_dict;
|
||||
extern std::map<std::string, Message *, case_insensitive_less> cmd_dict;
|
||||
|
||||
#endif /* INCLUDED_parse_h_h */
|
||||
|
|
|
@ -668,7 +668,6 @@ charybdis_main(int argc, char * const argv[])
|
|||
init_hash();
|
||||
clear_scache_hash_table(); /* server cache name table */
|
||||
init_host_hash();
|
||||
clear_hash_parse();
|
||||
init_client();
|
||||
init_hook();
|
||||
init_channels();
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
#include <ircd/packet.h>
|
||||
#include <ircd/s_assert.h>
|
||||
|
||||
rb_dictionary *cmd_dict = NULL;
|
||||
rb_dictionary *alias_dict = NULL;
|
||||
std::map<std::string, Message *, case_insensitive_less> cmd_dict;
|
||||
|
||||
static void cancel_clients(struct Client *, struct Client *);
|
||||
static void remove_unknown(struct Client *, const char *, char *);
|
||||
|
@ -131,7 +131,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
|
|||
}
|
||||
else
|
||||
{
|
||||
mptr = (Message *)rb_dictionary_retrieve(cmd_dict, msgbuf.cmd);
|
||||
mptr = cmd_dict[msgbuf.cmd];
|
||||
|
||||
/* no command or its encap only, error */
|
||||
if(!mptr || !mptr->cmd)
|
||||
|
@ -250,8 +250,7 @@ handle_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *so
|
|||
struct MessageEntry ehandler;
|
||||
MessageHandler handler = 0;
|
||||
|
||||
mptr = (Message *)rb_dictionary_retrieve(cmd_dict, command);
|
||||
|
||||
mptr = cmd_dict[command];
|
||||
if(mptr == NULL || mptr->cmd == NULL)
|
||||
return;
|
||||
|
||||
|
@ -265,20 +264,6 @@ handle_encap(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *so
|
|||
(*handler) (msgbuf_p, client_p, source_p, parc, parv);
|
||||
}
|
||||
|
||||
/*
|
||||
* clear_hash_parse()
|
||||
*
|
||||
* inputs -
|
||||
* output - NONE
|
||||
* side effects - MUST MUST be called at startup ONCE before
|
||||
* any other keyword hash routine is used.
|
||||
*/
|
||||
void
|
||||
clear_hash_parse()
|
||||
{
|
||||
cmd_dict = rb_dictionary_create("command", reinterpret_cast<int (*)(const void *, const void *)>(rb_strcasecmp));
|
||||
}
|
||||
|
||||
/* mod_add_cmd
|
||||
*
|
||||
* inputs - command name
|
||||
|
@ -295,7 +280,8 @@ mod_add_cmd(struct Message *msg)
|
|||
if(msg == NULL)
|
||||
return;
|
||||
|
||||
if (rb_dictionary_find(cmd_dict, msg->cmd) != NULL) {
|
||||
if (cmd_dict[msg->cmd] != NULL)
|
||||
{
|
||||
s_assert(0);
|
||||
return;
|
||||
}
|
||||
|
@ -304,7 +290,7 @@ mod_add_cmd(struct Message *msg)
|
|||
msg->rcount = 0;
|
||||
msg->bytes = 0;
|
||||
|
||||
rb_dictionary_add(cmd_dict, msg->cmd, msg);
|
||||
cmd_dict[msg->cmd] = msg;
|
||||
}
|
||||
|
||||
/* mod_del_cmd
|
||||
|
@ -320,8 +306,7 @@ mod_del_cmd(struct Message *msg)
|
|||
if(msg == NULL)
|
||||
return;
|
||||
|
||||
if (rb_dictionary_delete(cmd_dict, msg->cmd) == NULL)
|
||||
s_assert(0);
|
||||
cmd_dict.erase(msg->cmd);
|
||||
}
|
||||
|
||||
/* cancel_clients()
|
||||
|
|
|
@ -762,14 +762,11 @@ stats_klines(struct Client *source_p)
|
|||
static void
|
||||
stats_messages(struct Client *source_p)
|
||||
{
|
||||
rb_dictionary_iter iter;
|
||||
struct alias_entry *amsg;
|
||||
|
||||
void *elem;
|
||||
RB_DICTIONARY_FOREACH(elem, &iter, cmd_dict)
|
||||
for (auto it = cmd_dict.begin(); it != cmd_dict.end(); it++)
|
||||
{
|
||||
const auto msg(reinterpret_cast<Message *>(elem));
|
||||
const auto msg = it->second;
|
||||
s_assert(msg->cmd != NULL);
|
||||
|
||||
sendto_one_numeric(source_p, RPL_STATSCOMMANDS,
|
||||
form_str(RPL_STATSCOMMANDS),
|
||||
msg->cmd, msg->count,
|
||||
|
|
Loading…
Reference in a new issue