@@ -615,10 +615,11 @@ class GenericValue {
615
615
\tparam SourceAllocator allocator of \c rhs
616
616
\param rhs Value to copy from (read-only)
617
617
\param allocator Allocator for allocating copied elements and buffers. Commonly use GenericDocument::GetAllocator().
618
+ \param copyConstStrings Force copying of constant strings (e.g. referencing an in-situ buffer)
618
619
\see CopyFrom()
619
620
*/
620
621
template <typename SourceAllocator>
621
- GenericValue (const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator) {
622
+ GenericValue (const GenericValue<Encoding,SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false ) {
622
623
switch (rhs.GetType ()) {
623
624
case kObjectType : {
624
625
SizeType count = rhs.data_ .o .size ;
@@ -645,7 +646,7 @@ class GenericValue {
645
646
}
646
647
break ;
647
648
case kStringType :
648
- if (rhs.data_ .f .flags == kConstStringFlag ) {
649
+ if (rhs.data_ .f .flags == kConstStringFlag && !copyConstStrings ) {
649
650
data_.f .flags = rhs.data_ .f .flags ;
650
651
data_ = *reinterpret_cast <const Data*>(&rhs.data_ );
651
652
}
@@ -850,12 +851,13 @@ class GenericValue {
850
851
\tparam SourceAllocator Allocator type of \c rhs
851
852
\param rhs Value to copy from (read-only)
852
853
\param allocator Allocator to use for copying
854
+ \param copyConstStrings Force copying of constant strings (e.g. referencing an in-situ buffer)
853
855
*/
854
856
template <typename SourceAllocator>
855
- GenericValue& CopyFrom (const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator) {
857
+ GenericValue& CopyFrom (const GenericValue<Encoding, SourceAllocator>& rhs, Allocator& allocator, bool copyConstStrings = false ) {
856
858
RAPIDJSON_ASSERT (static_cast <void *>(this ) != static_cast <void const *>(&rhs));
857
859
this ->~GenericValue ();
858
- new (this ) GenericValue (rhs, allocator);
860
+ new (this ) GenericValue (rhs, allocator, copyConstStrings );
859
861
return *this ;
860
862
}
861
863
0 commit comments