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.

(Backported 65570f5 from master.)
  • Loading branch information
irydacea committed Oct 11, 2014
1 parent 37b531b commit 0b4e42a
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 @@ -277,7 +277,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 @@ -320,7 +321,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 0b4e42a

Please sign in to comment.