File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -235,23 +235,26 @@ Json::Value obj_value(Json::objectValue); // {}
235235 Value (const CppTL::ConstString& value);
236236#endif
237237 Value (bool value);
238+ // / Deep copy.
238239 Value (const Value& other);
239240 ~Value ();
240241
242+ // Deep copy, then swap(other).
241243 Value& operator =(Value other);
242- // / Swap values .
244+ // / Swap everything .
243245 void swap (Value& other);
246+ // / Swap values but leave comments and source offsets in place.
247+ void swapPayload (Value& other);
244248
245249 ValueType type () const ;
246250
251+ // / Compare payload only, not comments etc.
247252 bool operator <(const Value& other) const ;
248253 bool operator <=(const Value& other) const ;
249254 bool operator >=(const Value& other) const ;
250255 bool operator >(const Value& other) const ;
251-
252256 bool operator ==(const Value& other) const ;
253257 bool operator !=(const Value& other) const ;
254-
255258 int compare (const Value& other) const ;
256259
257260 const char * asCString () const ;
@@ -442,9 +445,6 @@ Json::Value obj_value(Json::objectValue); // {}
442445
443446 Value& resolveReference (const char * key, bool isStatic);
444447
445- // / Swap values but leave comments and source offsets in place.
446- void swapPayload (Value& other);
447-
448448#ifdef JSON_VALUE_USE_INTERNAL_MAP
449449 inline bool isItemAvailable () const { return itemIsUsed_ == 0 ; }
450450
Original file line number Diff line number Diff line change @@ -173,9 +173,12 @@ bool Reader::readValue() {
173173 currentValue ().setOffsetLimit (token.end_ - begin_);
174174 break ;
175175 case tokenNull:
176- currentValue () = Value ();
176+ {
177+ Value v;
178+ currentValue ().swapPayload (v);
177179 currentValue ().setOffsetStart (token.start_ - begin_);
178180 currentValue ().setOffsetLimit (token.end_ - begin_);
181+ }
179182 break ;
180183 case tokenArraySeparator:
181184 if (features_.allowDroppedNullPlaceholders_ ) {
@@ -393,7 +396,8 @@ bool Reader::readString() {
393396bool Reader::readObject (Token& tokenStart) {
394397 Token tokenName;
395398 std::string name;
396- currentValue () = Value (objectValue);
399+ Value init (objectValue);
400+ currentValue ().swapPayload (init);
397401 currentValue ().setOffsetStart (tokenStart.start_ - begin_);
398402 while (readToken (tokenName)) {
399403 bool initialTokenOk = true ;
@@ -486,7 +490,7 @@ bool Reader::decodeNumber(Token& token) {
486490 Value decoded;
487491 if (!decodeNumber (token, decoded))
488492 return false ;
489- currentValue () = decoded;
493+ currentValue (). swapPayload ( decoded) ;
490494 currentValue ().setOffsetStart (token.start_ - begin_);
491495 currentValue ().setOffsetLimit (token.end_ - begin_);
492496 return true ;
Original file line number Diff line number Diff line change @@ -406,7 +406,7 @@ Value::~Value() {
406406}
407407
408408Value& Value::operator =(Value other) {
409- swapPayload (other);
409+ swap (other);
410410 return *this ;
411411}
412412
You can’t perform that action at this time.
0 commit comments