Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp A. Hartmann <pah@qo.cx>2014-11-27 01:11:00 +0300
committerPhilipp A. Hartmann <pah@qo.cx>2014-11-27 01:11:00 +0300
commit2aab79207e5165190c360a0bc30eecae9e08306e (patch)
tree12753596f3083bd309a0c6edfbbdd06a021ed0a4 /include
parent28e55ee24d392ab0f011a2a47cb42a93e5b2a6e0 (diff)
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.
Diffstat (limited to 'include')
-rw-r--r--include/rapidjson/document.h23
1 files changed, 20 insertions, 3 deletions
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 <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