Add constexpr if possible

pull/836/head
Tatsuhiro Tsujikawa 2017-01-09 17:37:40 +09:00
parent 6abf2388cc
commit c1a0b33515
8 changed files with 28 additions and 27 deletions

View File

@ -151,7 +151,9 @@ void BtPieceMessage::doReceivedAction()
} }
} }
size_t BtPieceMessage::MESSAGE_HEADER_LENGTH = 13; namespace {
constexpr size_t MESSAGE_HEADER_LENGTH = 13;
} // namespace
void BtPieceMessage::createMessageHeader(unsigned char* msgHeader) const void BtPieceMessage::createMessageHeader(unsigned char* msgHeader) const
{ {

View File

@ -52,8 +52,6 @@ private:
DownloadContext* downloadContext_; DownloadContext* downloadContext_;
PeerStorage* peerStorage_; PeerStorage* peerStorage_;
static size_t MESSAGE_HEADER_LENGTH;
bool checkPieceHash(const std::shared_ptr<Piece>& piece); bool checkPieceHash(const std::shared_ptr<Piece>& piece);
void onNewPiece(const std::shared_ptr<Piece>& piece); void onNewPiece(const std::shared_ptr<Piece>& piece);

View File

@ -42,7 +42,7 @@
namespace aria2 { namespace aria2 {
ContentTypeRequestGroupCriteria::ContentTypeRequestGroupCriteria( ContentTypeRequestGroupCriteria::ContentTypeRequestGroupCriteria(
const char** contentTypes, const char** extensions) const char* const* contentTypes, const char* const* extensions)
: contentTypes_(contentTypes), extensions_(extensions) : contentTypes_(contentTypes), extensions_(extensions)
{ {
} }

View File

@ -43,12 +43,12 @@ namespace aria2 {
class ContentTypeRequestGroupCriteria : public RequestGroupCriteria { class ContentTypeRequestGroupCriteria : public RequestGroupCriteria {
private: private:
const char** contentTypes_; const char* const* contentTypes_;
const char** extensions_; const char* const* extensions_;
public: public:
ContentTypeRequestGroupCriteria(const char** contentTypes, ContentTypeRequestGroupCriteria(const char* const* contentTypes,
const char** extensions); const char* const* extensions);
virtual ~ContentTypeRequestGroupCriteria(); virtual ~ContentTypeRequestGroupCriteria();

View File

@ -37,32 +37,33 @@
namespace aria2 { namespace aria2 {
namespace { namespace {
const char* METALINK_EXTENSIONS[] = {".metalink", // Metalink3Spec constexpr const char* METALINK_EXTENSIONS[] = {".metalink", // Metalink3Spec
".meta4", // Metalink4Spec ".meta4", // Metalink4Spec
nullptr}; nullptr};
} // namespace } // namespace
const char** getMetalinkExtensions() { return METALINK_EXTENSIONS; } const char* const* getMetalinkExtensions() { return METALINK_EXTENSIONS; }
namespace { namespace {
const char* METALINK_CONTENT_TYPES[] = { constexpr const char* METALINK_CONTENT_TYPES[] = {
"application/metalink4+xml", // Metalink4Spec "application/metalink4+xml", // Metalink4Spec
"application/metalink+xml", // Metalink3Spec "application/metalink+xml", // Metalink3Spec
nullptr}; nullptr};
} // namespace } // namespace
const char** getMetalinkContentTypes() { return METALINK_CONTENT_TYPES; } const char* const* getMetalinkContentTypes() { return METALINK_CONTENT_TYPES; }
namespace { namespace {
const char* BT_EXTENSIONS[] = {".torrent", nullptr}; constexpr const char* BT_EXTENSIONS[] = {".torrent", nullptr};
} // namespace } // namespace
const char** getBtExtensions() { return BT_EXTENSIONS; } const char* const* getBtExtensions() { return BT_EXTENSIONS; }
namespace { namespace {
const char* BT_CONTENT_TYPES[] = {"application/x-bittorrent", nullptr}; constexpr const char* BT_CONTENT_TYPES[] = {"application/x-bittorrent",
nullptr};
} // namespace } // namespace
const char** getBtContentTypes() { return BT_CONTENT_TYPES; } const char* const* getBtContentTypes() { return BT_CONTENT_TYPES; }
} // namespace aria2 } // namespace aria2

View File

@ -41,13 +41,13 @@ namespace aria2 {
// These methods returns NULL-terminated list of c-strings. // These methods returns NULL-terminated list of c-strings.
const char** getMetalinkExtensions(); const char* const* getMetalinkExtensions();
const char** getMetalinkContentTypes(); const char* const* getMetalinkContentTypes();
const char** getBtExtensions(); const char* const* getBtExtensions();
const char** getBtContentTypes(); const char* const* getBtContentTypes();
} // namespace aria2 } // namespace aria2

View File

@ -220,7 +220,7 @@ bool HttpHeader::isKeepAlive() const
} }
namespace { namespace {
const char* INTERESTING_HEADER_NAMES[] = { constexpr const char* INTERESTING_HEADER_NAMES[] = {
"accept-encoding", "accept-encoding",
"access-control-request-headers", "access-control-request-headers",
"access-control-request-method", "access-control-request-method",
@ -249,9 +249,9 @@ const char* INTERESTING_HEADER_NAMES[] = {
int idInterestingHeader(const char* hdName) int idInterestingHeader(const char* hdName)
{ {
const char** i = std::lower_bound(std::begin(INTERESTING_HEADER_NAMES), auto i = std::lower_bound(std::begin(INTERESTING_HEADER_NAMES),
std::end(INTERESTING_HEADER_NAMES), hdName, std::end(INTERESTING_HEADER_NAMES), hdName,
util::strless); util::strless);
if (i != std::end(INTERESTING_HEADER_NAMES) && strcmp(*i, hdName) == 0) { if (i != std::end(INTERESTING_HEADER_NAMES) && strcmp(*i, hdName) == 0) {
return i - std::begin(INTERESTING_HEADER_NAMES); return i - std::begin(INTERESTING_HEADER_NAMES);
} }

View File

@ -41,7 +41,7 @@
namespace aria2 { namespace aria2 {
namespace { namespace {
const char* HELP_TAG_NAMES[] = { constexpr const char* HELP_TAG_NAMES[] = {
"#basic", "#advanced", "#http", "#https", "#ftp", "#basic", "#advanced", "#http", "#https", "#ftp",
"#metalink", "#bittorrent", "#cookie", "#hook", "#file", "#metalink", "#bittorrent", "#cookie", "#hook", "#file",
"#rpc", "#checksum", "#experimental", "#deprecated", "#help"}; "#rpc", "#checksum", "#experimental", "#deprecated", "#help"};