mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-09 11:09:32 +01:00
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
|
||||
GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator)
|
||||
{
|
||||
GenericDocument<Encoding,Allocator> d(&allocator);
|
||||
rhs.Accept(d);
|
||||
RawAssign(*d.stack_.template Pop<GenericValue>(1));
|
||||
switch (rhs.GetType()) {
|
||||
case kObjectType:
|
||||
case kArrayType: { // perform deep copy via SAX Handler
|
||||
GenericDocument<Encoding,Allocator> d(&allocator);
|
||||
rhs.Accept(d);
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user