[Pkg-bitcoin-commits] [libunivalue] 65/76: Prefer C++ STL vector .at() for accessing object values.

Jonas Smedegaard dr at jones.dk
Mon Apr 4 09:18:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libunivalue.

commit f2568bceafbbf5cd898adab012721833d2165584
Author: Jeff Garzik <jeff at bloq.com>
Date:   Sat Nov 7 11:43:30 2015 -0500

    Prefer C++ STL vector .at() for accessing object values.
---
 lib/univalue.cpp       | 18 +++++++-----------
 lib/univalue_write.cpp |  2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/univalue.cpp b/lib/univalue.cpp
index 332461c..0076d66 100644
--- a/lib/univalue.cpp
+++ b/lib/univalue.cpp
@@ -209,7 +209,7 @@ bool UniValue::pushKVs(const UniValue& obj)
 
     for (unsigned int i = 0; i < obj.keys.size(); i++) {
         keys.push_back(obj.keys[i]);
-        values.push_back(obj.values[i]);
+        values.push_back(obj.values.at(i));
     }
 
     return true;
@@ -233,7 +233,7 @@ bool UniValue::checkObject(const std::map<std::string,UniValue::VType>& t)
         if (idx < 0)
             return false;
 
-        if (values[idx].getType() != it->second)
+        if (values.at(idx).getType() != it->second)
             return false;
     }
 
@@ -249,7 +249,7 @@ const UniValue& UniValue::operator[](const std::string& key) const
     if (index < 0)
         return NullUniValue;
 
-    return values[index];
+    return values.at(index);
 }
 
 const UniValue& UniValue::operator[](unsigned int index) const
@@ -259,7 +259,7 @@ const UniValue& UniValue::operator[](unsigned int index) const
     if (index >= values.size())
         return NullUniValue;
 
-    return values[index];
+    return values.at(index);
 }
 
 const char *uvTypeName(UniValue::VType t)
@@ -277,15 +277,11 @@ const char *uvTypeName(UniValue::VType t)
     return NULL;
 }
 
-const UniValue& find_value( const UniValue& obj, const std::string& name)
+const UniValue& find_value(const UniValue& obj, const std::string& name)
 {
     for (unsigned int i = 0; i < obj.keys.size(); i++)
-    {
-        if( obj.keys[i] == name )
-        {
-            return obj.values[i];
-        }
-    }
+        if (obj.keys[i] == name)
+            return obj.values.at(i);
 
     return NullUniValue;
 }
diff --git a/lib/univalue_write.cpp b/lib/univalue_write.cpp
index fc528b7..ebb3c77 100644
--- a/lib/univalue_write.cpp
+++ b/lib/univalue_write.cpp
@@ -112,7 +112,7 @@ void UniValue::writeObject(unsigned int prettyIndent, unsigned int indentLevel,
         s += "\"" + json_escape(keys[i]) + "\":";
         if (prettyIndent)
             s += " ";
-        s += values[i].write(prettyIndent, indentLevel + 1);
+        s += values.at(i).write(prettyIndent, indentLevel + 1);
         if (i != (values.size() - 1))
             s += ",";
         if (prettyIndent)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libunivalue.git



More information about the Pkg-bitcoin-commits mailing list