Skip to content

Commit

Permalink
campaignd: Use const references or values where applicable
Browse files Browse the repository at this point in the history
Some old code used copies or read-write refererences for strings that
are never deliberately modified afterwards; and a bit of my own code
gets a (arguably tiny) WML config by value from a method that always
returns a read-only reference, missing out on a tiny optimization
opportunity by avoiding a config copy.

There was also a once-written int variable in handle_request_campaign().

(Backported fb5c5ab from master.)
  • Loading branch information
irydacea committed Oct 11, 2014
1 parent d9b023e commit ec94324
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -356,16 +356,16 @@ void server::handle_request_campaign_list(const server::request& req)
after_flag = true;
} catch(bad_lexical_cast) {}

std::string name = req.cfg["name"];
std::string lang = req.cfg["language"];
const std::string& name = req.cfg["name"];
const std::string& lang = req.cfg["language"];

BOOST_FOREACH(const config& i, campaigns().child_range("campaign"))
{
if(!name.empty() && name != i["name"]) {
continue;
}

std::string tm = i["timestamp"];
const std::string& tm = i["timestamp"];

if (before_flag && (tm.empty() || lexical_cast_default<time_t>(tm, 0) >= before)) {
continue;
Expand Down Expand Up @@ -402,7 +402,7 @@ void server::handle_request_campaign_list(const server::request& req)

// Build a feedback_url string attribute from the
// internal [feedback] data.
config url_params = j.child_or_empty("feedback");
const config& url_params = j.child_or_empty("feedback");
j.clear_children("feedback");

if(!url_params.empty() && !feedback_url_format_.empty()) {
Expand Down Expand Up @@ -440,7 +440,7 @@ void server::handle_request_campaign(const server::request& req)
// the downloads count. Default to true for compatibility with old
// clients that won't tell us what they are trying to do.
if(req.cfg["increase_downloads"].to_bool(true)) {
int downloads = campaign["downloads"].to_int() + 1;
const int downloads = campaign["downloads"].to_int() + 1;
campaign["downloads"] = downloads;
}
}
Expand Down Expand Up @@ -577,7 +577,7 @@ void server::handle_upload(const server::request& req)
(*campaign).add_child("feedback", url_params);
}

std::string filename = (*campaign)["filename"].str();
const std::string& filename = (*campaign)["filename"].str();
data["title"] = (*campaign)["title"];
data["name"] = "";
data["campaign_name"] = (*campaign)["name"];
Expand Down Expand Up @@ -695,7 +695,7 @@ int main(int argc, char**argv)
try {
printf("argc %d argv[0] %s 1 %s\n",argc,argv[0],argv[1]);

std::string cfg_path = normalize_path("server.cfg");
const std::string& cfg_path = normalize_path("server.cfg");

if(argc >= 2 && atoi(argv[1])){
campaignd::server(cfg_path, atoi(argv[1])).run();
Expand Down

0 comments on commit ec94324

Please sign in to comment.