From 8eb5d89db60d6f9265a4ea1c86643b83f9d5114a Mon Sep 17 00:00:00 2001 From: Billy Donahue Date: Mon, 10 Nov 2014 01:35:42 -0500 Subject: [PATCH] Remove initInt and initUInt until they are needed. --- include/json/value.h | 2 + src/lib_json/json_value.cpp | 139 ++++++++++-------------------------- 2 files changed, 40 insertions(+), 101 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index a60ca8f..197a856 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -440,6 +440,8 @@ Json::Value obj_value(Json::objectValue); // {} size_t getOffsetLimit() const; private: + void initBasic(ValueType type, bool allocated = false); + Value& resolveReference(const char* key, bool isStatic); #ifdef JSON_VALUE_USE_INTERNAL_MAP diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 2a0b97b..b6ea8ff 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -225,14 +225,8 @@ bool Value::CZString::isStaticString() const { return index_ == noDuplication; } * memset( this, 0, sizeof(Value) ) * This optimization is used in ValueInternalMap fast allocator. */ -Value::Value(ValueType type) - : type_(type), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(ValueType type) { + initBasic(type); switch (type) { case nullValue: break; @@ -267,130 +261,62 @@ Value::Value(ValueType type) } } -Value::Value(UInt value) - : type_(uintValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(Int value) { + initBasic(intValue); + value_.int_ = value; +} + +Value::Value(UInt value) { + initBasic(uintValue); value_.uint_ = value; } - -Value::Value(Int value) - : type_(intValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { - value_.int_ = value; -} - #if defined(JSON_HAS_INT64) -Value::Value(Int64 value) - : type_(intValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(Int64 value) { + initBasic(intValue); value_.int_ = value; } - -Value::Value(UInt64 value) - : type_(uintValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(UInt64 value) { + initBasic(uintValue); value_.uint_ = value; } #endif // defined(JSON_HAS_INT64) -Value::Value(double value) - : type_(realValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(double value) { + initBasic(realValue); value_.real_ = value; } -Value::Value(const char* value) - : type_(stringValue), allocated_(true) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(const char* value) { + initBasic(stringValue, true); value_.string_ = duplicateStringValue(value); } -Value::Value(const char* beginValue, const char* endValue) - : type_(stringValue), allocated_(true) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(const char* beginValue, const char* endValue) { + initBasic(stringValue, true); value_.string_ = duplicateStringValue(beginValue, (unsigned int)(endValue - beginValue)); } -Value::Value(const std::string& value) - : type_(stringValue), allocated_(true) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(const std::string& value) { + initBasic(stringValue, true); value_.string_ = duplicateStringValue(value.c_str(), (unsigned int)value.length()); } -Value::Value(const StaticString& value) - : type_(stringValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(const StaticString& value) { + initBasic(stringValue); value_.string_ = const_cast(value.c_str()); } #ifdef JSON_USE_CPPTL -Value::Value(const CppTL::ConstString& value) - : type_(stringValue), allocated_(true) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(const CppTL::ConstString& value) { + initBasic(stringValue, true); value_.string_ = duplicateStringValue(value, value.length()); } #endif -Value::Value(bool value) - : type_(booleanValue), allocated_(false) -#ifdef JSON_VALUE_USE_INTERNAL_MAP - , - itemIsUsed_(0) -#endif - , - comments_(0), start_(0), limit_(0) { +Value::Value(bool value) { + initBasic(booleanValue); value_.bool_ = value; } @@ -966,6 +892,17 @@ Value& Value::operator[](const char* key) { return resolveReference(key, false); } +void Value::initBasic(ValueType type, bool allocated) { + type_ = type; + allocated_ = allocated; +#ifdef JSON_VALUE_USE_INTERNAL_MAP + itemIsUsed_ = 0; +#endif + comments_ = 0; + start_ = 0; + limit_ = 0; +} + Value& Value::resolveReference(const char* key, bool isStatic) { JSON_ASSERT_MESSAGE( type_ == nullValue || type_ == objectValue,