diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 047bc667..56e2f2e8 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1896,9 +1896,26 @@ template inline GenericValue::GenericValue(const GenericValue& rhs, Allocator& allocator) { - GenericDocument d(&allocator); - rhs.Accept(d); - RawAssign(*d.stack_.template Pop(1)); + switch (rhs.GetType()) { + case kObjectType: + case kArrayType: { // perform deep copy via SAX Handler + GenericDocument d(&allocator); + rhs.Accept(d); + RawAssign(*d.stack_.template Pop(1)); + } + break; + case kStringType: + if (rhs.flags_ == kConstStringFlag) { + flags_ = rhs.flags_; + data_ = *reinterpret_cast(&rhs.data_); + } else { + SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator); + } + break; + default: // kNumberType, kTrueType, kFalseType, kNullType + flags_ = rhs.flags_; + data_ = *reinterpret_cast(&rhs.data_); + } } RAPIDJSON_NAMESPACE_END