summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2017-01-09 17:37:40 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2017-01-09 17:37:40 +0900
commitc1a0b335159a6d002f4cc35f0b66397af0f39759 (patch)
treea31062fb3e8f486bd08552783b7a2afa0b9dab36
parent6abf2388ccec6332d03bb6e606227d5f527f24d9 (diff)
Add constexpr if possible
-rw-r--r--src/BtPieceMessage.cc4
-rw-r--r--src/BtPieceMessage.h2
-rw-r--r--src/ContentTypeRequestGroupCriteria.cc2
-rw-r--r--src/ContentTypeRequestGroupCriteria.h8
-rw-r--r--src/DownloadHandlerConstants.cc21
-rw-r--r--src/DownloadHandlerConstants.h8
-rw-r--r--src/HttpHeader.cc8
-rw-r--r--src/help_tags.cc2
8 files changed, 28 insertions, 27 deletions
diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc
index 54c676ba..c63ef91f 100644
--- a/src/BtPieceMessage.cc
+++ b/src/BtPieceMessage.cc
@@ -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
{
diff --git a/src/BtPieceMessage.h b/src/BtPieceMessage.h
index 58d73f29..e40e3a2c 100644
--- a/src/BtPieceMessage.h
+++ b/src/BtPieceMessage.h
@@ -52,8 +52,6 @@ private:
DownloadContext* downloadContext_;
PeerStorage* peerStorage_;
- static size_t MESSAGE_HEADER_LENGTH;
-
bool checkPieceHash(const std::shared_ptr<Piece>& piece);
void onNewPiece(const std::shared_ptr<Piece>& piece);
diff --git a/src/ContentTypeRequestGroupCriteria.cc b/src/ContentTypeRequestGroupCriteria.cc
index 03aa833e..9982c40c 100644
--- a/src/ContentTypeRequestGroupCriteria.cc
+++ b/src/ContentTypeRequestGroupCriteria.cc
@@ -42,7 +42,7 @@
namespace aria2 {
ContentTypeRequestGroupCriteria::ContentTypeRequestGroupCriteria(
- const char** contentTypes, const char** extensions)
+ const char* const* contentTypes, const char* const* extensions)
: contentTypes_(contentTypes), extensions_(extensions)
{
}
diff --git a/src/ContentTypeRequestGroupCriteria.h b/src/ContentTypeRequestGroupCriteria.h
index b5a8bd14..9c1f1257 100644
--- a/src/ContentTypeRequestGroupCriteria.h
+++ b/src/ContentTypeRequestGroupCriteria.h
@@ -43,12 +43,12 @@ namespace aria2 {
class ContentTypeRequestGroupCriteria : public RequestGroupCriteria {
private:
- const char** contentTypes_;
- const char** extensions_;
+ const char* const* contentTypes_;
+ const char* const* extensions_;
public:
- ContentTypeRequestGroupCriteria(const char** contentTypes,
- const char** extensions);
+ ContentTypeRequestGroupCriteria(const char* const* contentTypes,
+ const char* const* extensions);
virtual ~ContentTypeRequestGroupCriteria();
diff --git a/src/DownloadHandlerConstants.cc b/src/DownloadHandlerConstants.cc
index 365c2e01..e189e7e4 100644
--- a/src/DownloadHandlerConstants.cc
+++ b/src/DownloadHandlerConstants.cc
@@ -37,32 +37,33 @@
namespace aria2 {
namespace {
-const char* METALINK_EXTENSIONS[] = {".metalink", // Metalink3Spec
- ".meta4", // Metalink4Spec
- nullptr};
+constexpr const char* METALINK_EXTENSIONS[] = {".metalink", // Metalink3Spec
+ ".meta4", // Metalink4Spec
+ nullptr};
} // namespace
-const char** getMetalinkExtensions() { return METALINK_EXTENSIONS; }
+const char* const* getMetalinkExtensions() { return METALINK_EXTENSIONS; }
namespace {
-const char* METALINK_CONTENT_TYPES[] = {
+constexpr const char* METALINK_CONTENT_TYPES[] = {
"application/metalink4+xml", // Metalink4Spec
"application/metalink+xml", // Metalink3Spec
nullptr};
} // namespace
-const char** getMetalinkContentTypes() { return METALINK_CONTENT_TYPES; }
+const char* const* getMetalinkContentTypes() { return METALINK_CONTENT_TYPES; }
namespace {
-const char* BT_EXTENSIONS[] = {".torrent", nullptr};
+constexpr const char* BT_EXTENSIONS[] = {".torrent", nullptr};
} // namespace
-const char** getBtExtensions() { return BT_EXTENSIONS; }
+const char* const* getBtExtensions() { return BT_EXTENSIONS; }
namespace {
-const char* BT_CONTENT_TYPES[] = {"application/x-bittorrent", nullptr};
+constexpr const char* BT_CONTENT_TYPES[] = {"application/x-bittorrent",
+ nullptr};
} // namespace
-const char** getBtContentTypes() { return BT_CONTENT_TYPES; }
+const char* const* getBtContentTypes() { return BT_CONTENT_TYPES; }
} // namespace aria2
diff --git a/src/DownloadHandlerConstants.h b/src/DownloadHandlerConstants.h
index 7d05c676..8cc1b1ee 100644
--- a/src/DownloadHandlerConstants.h
+++ b/src/DownloadHandlerConstants.h
@@ -41,13 +41,13 @@ namespace aria2 {
// 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
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index cc75e4d5..bcb6a9ec 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -220,7 +220,7 @@ bool HttpHeader::isKeepAlive() const
}
namespace {
-const char* INTERESTING_HEADER_NAMES[] = {
+constexpr const char* INTERESTING_HEADER_NAMES[] = {
"accept-encoding",
"access-control-request-headers",
"access-control-request-method",
@@ -249,9 +249,9 @@ const char* INTERESTING_HEADER_NAMES[] = {
int idInterestingHeader(const char* hdName)
{
- const char** i = std::lower_bound(std::begin(INTERESTING_HEADER_NAMES),
- std::end(INTERESTING_HEADER_NAMES), hdName,
- util::strless);
+ auto i = std::lower_bound(std::begin(INTERESTING_HEADER_NAMES),
+ std::end(INTERESTING_HEADER_NAMES), hdName,
+ util::strless);
if (i != std::end(INTERESTING_HEADER_NAMES) && strcmp(*i, hdName) == 0) {
return i - std::begin(INTERESTING_HEADER_NAMES);
}
diff --git a/src/help_tags.cc b/src/help_tags.cc
index ae5f57fc..efa8de5d 100644
--- a/src/help_tags.cc
+++ b/src/help_tags.cc
@@ -41,7 +41,7 @@
namespace aria2 {
namespace {
-const char* HELP_TAG_NAMES[] = {
+constexpr const char* HELP_TAG_NAMES[] = {
"#basic", "#advanced", "#http", "#https", "#ftp",
"#metalink", "#bittorrent", "#cookie", "#hook", "#file",
"#rpc", "#checksum", "#experimental", "#deprecated", "#help"};