Skip to content

Commit

Permalink
campaignd: Replace vector<pair<k,v>> with map<k,v> for the handlers t…
Browse files Browse the repository at this point in the history
…able

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.
  • Loading branch information
irydacea committed Jun 14, 2014
1 parent 81874be commit 65570f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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) \
Expand Down
3 changes: 1 addition & 2 deletions src/campaign_server/campaign_server.hpp
Expand Up @@ -79,7 +79,6 @@ class server : private boost::noncopyable
};

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_;
Expand All @@ -90,7 +89,7 @@ class server : private boost::noncopyable
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_;

Expand Down

0 comments on commit 65570f5

Please sign in to comment.