@@ -163,14 +163,20 @@ bool Reader::readValue() {
163
163
successful = decodeString (token);
164
164
break ;
165
165
case tokenTrue:
166
- currentValue () = true ;
166
+ {
167
+ Value v (true );
168
+ currentValue ().swapPayload (v);
167
169
currentValue ().setOffsetStart (token.start_ - begin_);
168
170
currentValue ().setOffsetLimit (token.end_ - begin_);
171
+ }
169
172
break ;
170
173
case tokenFalse:
171
- currentValue () = false ;
174
+ {
175
+ Value v (false );
176
+ currentValue ().swapPayload (v);
172
177
currentValue ().setOffsetStart (token.start_ - begin_);
173
178
currentValue ().setOffsetLimit (token.end_ - begin_);
179
+ }
174
180
break ;
175
181
case tokenNull:
176
182
{
@@ -185,7 +191,8 @@ bool Reader::readValue() {
185
191
// "Un-read" the current token and mark the current value as a null
186
192
// token.
187
193
current_--;
188
- currentValue () = Value ();
194
+ Value v;
195
+ currentValue ().swapPayload (v);
189
196
currentValue ().setOffsetStart (current_ - begin_ - 1 );
190
197
currentValue ().setOffsetLimit (current_ - begin_);
191
198
break ;
@@ -450,7 +457,8 @@ bool Reader::readObject(Token& tokenStart) {
450
457
}
451
458
452
459
bool Reader::readArray (Token& tokenStart) {
453
- currentValue () = Value (arrayValue);
460
+ Value init (arrayValue);
461
+ currentValue ().swapPayload (init);
454
462
currentValue ().setOffsetStart (tokenStart.start_ - begin_);
455
463
skipSpaces ();
456
464
if (*current_ == ' ]' ) // empty array
@@ -540,7 +548,7 @@ bool Reader::decodeDouble(Token& token) {
540
548
Value decoded;
541
549
if (!decodeDouble (token, decoded))
542
550
return false ;
543
- currentValue () = decoded;
551
+ currentValue (). swapPayload ( decoded) ;
544
552
currentValue ().setOffsetStart (token.start_ - begin_);
545
553
currentValue ().setOffsetLimit (token.end_ - begin_);
546
554
return true ;
@@ -583,10 +591,11 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
583
591
}
584
592
585
593
bool Reader::decodeString (Token& token) {
586
- std::string decoded ;
587
- if (!decodeString (token, decoded ))
594
+ std::string decoded_string ;
595
+ if (!decodeString (token, decoded_string ))
588
596
return false ;
589
- currentValue () = decoded;
597
+ Value decoded (decoded_string);
598
+ currentValue ().swapPayload (decoded);
590
599
currentValue ().setOffsetStart (token.start_ - begin_);
591
600
currentValue ().setOffsetLimit (token.end_ - begin_);
592
601
return true ;
0 commit comments