GenericValue: improve copying performance
The GenericValue "copy" constructor (with Allocator) uses a temporary GenericDocument object to perform the deep copying with the provided allocator. This leads to the temporary allocation of the `Stack` memory, even in case of shallow values (numbers, etc.). This patch improves the performance of this operation by only resorting the the SAX Handler implementation in case of Array or Object values.
This commit is contained in:
parent
28e55ee24d
commit
2aab79207e
@ -1896,9 +1896,26 @@ template <typename SourceAllocator>
|
||||
inline
|
||||
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);
|
||||
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