@@ -163,14 +163,20 @@ bool Reader::readValue() {
163163 successful = decodeString (token);
164164 break ;
165165 case tokenTrue:
166- currentValue () = true ;
166+ {
167+ Value v (true );
168+ currentValue ().swapPayload (v);
167169 currentValue ().setOffsetStart (token.start_ - begin_);
168170 currentValue ().setOffsetLimit (token.end_ - begin_);
171+ }
169172 break ;
170173 case tokenFalse:
171- currentValue () = false ;
174+ {
175+ Value v (false );
176+ currentValue ().swapPayload (v);
172177 currentValue ().setOffsetStart (token.start_ - begin_);
173178 currentValue ().setOffsetLimit (token.end_ - begin_);
179+ }
174180 break ;
175181 case tokenNull:
176182 {
@@ -185,7 +191,8 @@ bool Reader::readValue() {
185191 // "Un-read" the current token and mark the current value as a null
186192 // token.
187193 current_--;
188- currentValue () = Value ();
194+ Value v;
195+ currentValue ().swapPayload (v);
189196 currentValue ().setOffsetStart (current_ - begin_ - 1 );
190197 currentValue ().setOffsetLimit (current_ - begin_);
191198 break ;
@@ -450,7 +457,8 @@ bool Reader::readObject(Token& tokenStart) {
450457}
451458
452459bool Reader::readArray (Token& tokenStart) {
453- currentValue () = Value (arrayValue);
460+ Value init (arrayValue);
461+ currentValue ().swapPayload (init);
454462 currentValue ().setOffsetStart (tokenStart.start_ - begin_);
455463 skipSpaces ();
456464 if (*current_ == ' ]' ) // empty array
@@ -540,7 +548,7 @@ bool Reader::decodeDouble(Token& token) {
540548 Value decoded;
541549 if (!decodeDouble (token, decoded))
542550 return false ;
543- currentValue () = decoded;
551+ currentValue (). swapPayload ( decoded) ;
544552 currentValue ().setOffsetStart (token.start_ - begin_);
545553 currentValue ().setOffsetLimit (token.end_ - begin_);
546554 return true ;
@@ -583,10 +591,11 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
583591}
584592
585593bool Reader::decodeString (Token& token) {
586- std::string decoded ;
587- if (!decodeString (token, decoded ))
594+ std::string decoded_string ;
595+ if (!decodeString (token, decoded_string ))
588596 return false ;
589- currentValue () = decoded;
597+ Value decoded (decoded_string);
598+ currentValue ().swapPayload (decoded);
590599 currentValue ().setOffsetStart (token.start_ - begin_);
591600 currentValue ().setOffsetLimit (token.end_ - begin_);
592601 return true ;
0 commit comments