Merge pull request #206 from pah/enhance/optimize-value-copy
GenericValue: improve copying performance
This commit is contained in:
commit
7eee4303c7
@ -1896,9 +1896,26 @@ template <typename SourceAllocator>
|
|||||||
inline
|
inline
|
||||||
GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator)
|
GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator)
|
||||||
{
|
{
|
||||||
|
switch (rhs.GetType()) {
|
||||||
|
case kObjectType:
|
||||||
|
case kArrayType: { // perform deep copy via SAX Handler
|
||||||
GenericDocument<Encoding,Allocator> d(&allocator);
|
GenericDocument<Encoding,Allocator> d(&allocator);
|
||||||
rhs.Accept(d);
|
rhs.Accept(d);
|
||||||
RawAssign(*d.stack_.template Pop<GenericValue>(1));
|
RawAssign(*d.stack_.template Pop<GenericValue>(1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case kStringType:
|
||||||
|
if (rhs.flags_ == kConstStringFlag) {
|
||||||
|
flags_ = rhs.flags_;
|
||||||
|
data_ = *reinterpret_cast<const Data*>(&rhs.data_);
|
||||||
|
} else {
|
||||||
|
SetStringRaw(StringRef(rhs.GetString(), rhs.GetStringLength()), allocator);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: // kNumberType, kTrueType, kFalseType, kNullType
|
||||||
|
flags_ = rhs.flags_;
|
||||||
|
data_ = *reinterpret_cast<const Data*>(&rhs.data_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RAPIDJSON_NAMESPACE_END
|
RAPIDJSON_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user