campaignd: Replace vector<pair<k,v>> with map<k,v> for the handlers table

std::vector<std::pair<k,v>> has worse look-up performance than
std::map<k,v> in general, not that the difference is too noticeable for
such a small dataset like campaignd's handlers table, that is built in
such a way its items are arranged in descending order of usage
frequency.

It still feels like this is the best thing to do to keep future
maintainers sane.
This commit is contained in:
Ignacio R. Morelle 2014-06-14 01:13:35 -04:00
parent 81874be9f9
commit 65570f5cb9
2 changed files with 4 additions and 4 deletions

View file

@ -278,7 +278,8 @@ void server::run()
while((sock = network::receive_data(data, 0)) != network::null_connection)
{
BOOST_FOREACH(const request_handler_info& rh, handlers_)
typedef std::pair<std::string, request_handler> rh_table_entry;
BOOST_FOREACH(const rh_table_entry& rh, handlers_)
{
const config& req_body = data.child(rh.first);
@ -321,7 +322,7 @@ void server::run()
void server::register_handler(const std::string& cmd, const request_handler& func)
{
handlers_.push_back(std::make_pair(cmd, func));
handlers_[cmd] = func;
}
#define REGISTER_CAMPAIGND_HANDLER(req_id) \

View file

@ -79,7 +79,6 @@ private:
};
typedef boost::function<void (const request& req)> request_handler;
typedef std::pair<std::string, request_handler> request_handler_info;
config cfg_;
const std::string cfg_file_;
@ -90,7 +89,7 @@ private:
boost::scoped_ptr<input_stream> input_; /**< Server control socket. */
std::map<std::string, std::string> hooks_;
std::vector<request_handler_info> handlers_;
std::map<std::string, request_handler> handlers_;
std::string feedback_url_format_;