[icinga-checkins] icinga.org: icinga2/master: Avoid unnecessary string copies in the JSON encoder

git at icinga.org git at icinga.org
Sat Aug 27 12:26:14 CEST 2016


Module: icinga2
Branch: master
Commit: 00eec13338dd2ad76d4390146f9a3884f57a77a9
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=00eec13338dd2ad76d4390146f9a3884f57a77a9

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Aug 27 11:47:36 2016 +0200

Avoid unnecessary string copies in the JSON encoder

refs #12509

---

 lib/base/json.cpp  |    5 +----
 lib/base/value.hpp |    6 +++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/lib/base/json.cpp b/lib/base/json.cpp
index de15525..0ae2fd3 100644
--- a/lib/base/json.cpp
+++ b/lib/base/json.cpp
@@ -66,8 +66,6 @@ static void EncodeArray(yajl_gen handle, const Array::Ptr& arr)
 
 static void Encode(yajl_gen handle, const Value& value)
 {
-	String str;
-
 	switch (value.GetType()) {
 		case ValueNumber:
 			if (yajl_gen_double(handle, static_cast<double>(value)) == yajl_gen_invalid_number)
@@ -79,8 +77,7 @@ static void Encode(yajl_gen handle, const Value& value)
 
 			break;
 		case ValueString:
-			str = value;
-			yajl_gen_string(handle, reinterpret_cast<const unsigned char *>(str.CStr()), str.GetLength());
+			yajl_gen_string(handle, reinterpret_cast<const unsigned char *>(value.Get<String>().CStr()), value.Get<String>().GetLength());
 
 			break;
 		case ValueObject:
diff --git a/lib/base/value.hpp b/lib/base/value.hpp
index 68a2250..5beba9e 100644
--- a/lib/base/value.hpp
+++ b/lib/base/value.hpp
@@ -256,14 +256,14 @@ public:
 	
 	Value Clone(void) const;
 
-private:
-	boost::variant<boost::blank, double, bool, String, Object::Ptr> m_Value;
-
 	template<typename T>
 	const T& Get(void) const
 	{
 		return boost::get<T>(m_Value);
 	}
+
+private:
+	boost::variant<boost::blank, double, bool, String, Object::Ptr> m_Value;
 };
 
 extern I2_BASE_API Value Empty;



More information about the icinga-checkins mailing list