diff --git a/src/ServerStat.cc b/src/ServerStat.cc index 23bae375..7bf9fdd1 100644 --- a/src/ServerStat.cc +++ b/src/ServerStat.cc @@ -46,10 +46,12 @@ namespace aria2 { -const std::string ServerStat::STATUS_STRING[] = { +namespace { +const char* STATUS_STRING[] = { "OK", "ERROR" }; +} // namespace ServerStat::ServerStat(const std::string& hostname, const std::string& protocol) : hostname_(hostname), @@ -161,18 +163,18 @@ void ServerStat::setStatus(STATUS status) void ServerStat::setStatus(const std::string& status) { - const std::string* p = std::find(vbegin(STATUS_STRING), vend(STATUS_STRING), - status); - if(p != vend(STATUS_STRING)) { - status_ = static_cast(ServerStat::OK+ - std::distance(vbegin(STATUS_STRING), p)); + for(int i = 0; i < MAX_STATUS; ++i) { + if(strcmp(status.c_str(), STATUS_STRING[i]) == 0) { + status_ = static_cast(i); + break; + } } } void ServerStat::setStatusInternal(STATUS status) { A2_LOG_DEBUG(fmt("ServerStat: set status %s for %s (%s)", - STATUS_STRING[status].c_str(), + STATUS_STRING[status], hostname_.c_str(), protocol_.c_str())); status_ = status; @@ -211,7 +213,7 @@ std::string ServerStat::toString() const getMultiConnectionAvgSpeed(), getLastUpdated().getTime(), getCounter(), - ServerStat::STATUS_STRING[getStatus()].c_str()); + STATUS_STRING[getStatus()]); } } // namespace aria2 diff --git a/src/ServerStat.h b/src/ServerStat.h index 357af0eb..03eedd52 100644 --- a/src/ServerStat.h +++ b/src/ServerStat.h @@ -52,10 +52,9 @@ class ServerStat { public: enum STATUS { OK = 0, - A2_ERROR + A2_ERROR, + MAX_STATUS }; - - static const std::string STATUS_STRING[]; ServerStat(const std::string& hostname, const std::string& protocol);