From 0a95211100736cabe19428eb73383cb5b8062e37 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 18 May 2008 10:14:53 +0000 Subject: [PATCH] 2008-05-18 Tatsuhiro Tsujikawa Made Option::get(...) return const reference of std::string. * src/Option.cc * src/Option.h --- ChangeLog | 6 ++++++ src/Option.cc | 17 +++++++++-------- src/Option.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97cdb1cb..76d24ce6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-05-18 Tatsuhiro Tsujikawa + + Made Option::get(...) return const reference of std::string. + * src/Option.cc + * src/Option.h + 2008-05-18 Tatsuhiro Tsujikawa Replaced std:copy with insert. 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 +#include 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::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;