summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-05-18 10:14:53 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-05-18 10:14:53 +0000
commit0a95211100736cabe19428eb73383cb5b8062e37 (patch)
treea88367b57e7eaf52a094a93a5ff20eef6bc505d1 /src
parente4b0446c610bf4bba4537901adbfb6f2a714a167 (diff)
2008-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made Option::get(...) return const reference of std::string. * src/Option.cc * src/Option.h
Diffstat (limited to 'src')
-rw-r--r--src/Option.cc17
-rw-r--r--src/Option.h2
2 files changed, 10 insertions, 9 deletions
diff --git a/src/Option.cc b/src/Option.cc
index a3b11684..3d135203 100644
--- a/src/Option.cc
+++ b/src/Option.cc
@@ -36,6 +36,7 @@
#include "prefs.h"
#include "A2STR.h"
#include <cstdlib>
+#include <cstring>
namespace aria2 {
@@ -51,7 +52,7 @@ bool Option::defined(const std::string& name) const {
return table.count(name) == 1;
}
-std::string Option::get(const std::string& name) const {
+const std::string& Option::get(const std::string& name) const {
std::map<std::string, std::string>::const_iterator itr = table.find(name);
if(itr == table.end()) {
return A2STR::NIL;
@@ -61,26 +62,26 @@ std::string Option::get(const std::string& name) const {
}
int32_t Option::getAsInt(const std::string& name) const {
- std::string value = get(name);
+ const std::string& value = get(name);
if(value.empty()) {
return 0;
} else {
- return strtol(value.c_str(), NULL, 10);
+ return strtol(value.c_str(), 0, 10);
}
}
int64_t Option::getAsLLInt(const std::string& name) const {
- std::string value = get(name);
+ const std::string& value = get(name);
if(value.empty()) {
return 0;
} else {
- return strtoll(value.c_str(), NULL, 10);
+ return strtoll(value.c_str(), 0, 10);
}
}
bool Option::getAsBool(const std::string& name) const {
- std::string value = get(name);
- if(value == V_TRUE) {
+ const std::string& value = get(name);
+ if(strcmp(value.c_str(), V_TRUE) == 0) {
return true;
} else {
return false;
@@ -88,7 +89,7 @@ bool Option::getAsBool(const std::string& name) const {
}
double Option::getAsDouble(const std::string& name) const {
- std::string value = get(name);
+ const std::string& value = get(name);
if(value.empty()) {
return 0.0;
} else {
diff --git a/src/Option.h b/src/Option.h
index aa4ca1e8..f95ee373 100644
--- a/src/Option.h
+++ b/src/Option.h
@@ -50,7 +50,7 @@ public:
void put(const std::string& name, const std::string& value);
bool defined(const std::string& name) const;
- std::string get(const std::string& name) const;
+ const std::string& get(const std::string& name) const;
int getAsInt(const std::string& name) const;
int64_t getAsLLInt(const std::string& name) const;
bool getAsBool(const std::string& name) const;