瀏覽代碼

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
Tatsuhiro Tsujikawa 17 年之前
父節點
當前提交
0a95211100
共有 3 個文件被更改,包括 16 次插入9 次删除
  1. 6 0
      ChangeLog
  2. 9 8
      src/Option.cc
  3. 1 1
      src/Option.h

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+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
+
 2008-05-18  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Replaced std:copy with insert.

+ 9 - 8
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 {

+ 1 - 1
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;