File tree Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -235,23 +235,26 @@ Json::Value obj_value(Json::objectValue); // {}
235
235
Value (const CppTL::ConstString& value);
236
236
#endif
237
237
Value (bool value);
238
+ // / Deep copy.
238
239
Value (const Value& other);
239
240
~Value ();
240
241
242
+ // Deep copy, then swap(other).
241
243
Value& operator =(Value other);
242
- // / Swap values .
244
+ // / Swap everything .
243
245
void swap (Value& other);
246
+ // / Swap values but leave comments and source offsets in place.
247
+ void swapPayload (Value& other);
244
248
245
249
ValueType type () const ;
246
250
251
+ // / Compare payload only, not comments etc.
247
252
bool operator <(const Value& other) const ;
248
253
bool operator <=(const Value& other) const ;
249
254
bool operator >=(const Value& other) const ;
250
255
bool operator >(const Value& other) const ;
251
-
252
256
bool operator ==(const Value& other) const ;
253
257
bool operator !=(const Value& other) const ;
254
-
255
258
int compare (const Value& other) const ;
256
259
257
260
const char * asCString () const ;
@@ -442,9 +445,6 @@ Json::Value obj_value(Json::objectValue); // {}
442
445
443
446
Value& resolveReference (const char * key, bool isStatic);
444
447
445
- // / Swap values but leave comments and source offsets in place.
446
- void swapPayload (Value& other);
447
-
448
448
#ifdef JSON_VALUE_USE_INTERNAL_MAP
449
449
inline bool isItemAvailable () const { return itemIsUsed_ == 0 ; }
450
450
Original file line number Diff line number Diff line change @@ -173,9 +173,12 @@ bool Reader::readValue() {
173
173
currentValue ().setOffsetLimit (token.end_ - begin_);
174
174
break ;
175
175
case tokenNull:
176
- currentValue () = Value ();
176
+ {
177
+ Value v;
178
+ currentValue ().swapPayload (v);
177
179
currentValue ().setOffsetStart (token.start_ - begin_);
178
180
currentValue ().setOffsetLimit (token.end_ - begin_);
181
+ }
179
182
break ;
180
183
case tokenArraySeparator:
181
184
if (features_.allowDroppedNullPlaceholders_ ) {
@@ -393,7 +396,8 @@ bool Reader::readString() {
393
396
bool Reader::readObject (Token& tokenStart) {
394
397
Token tokenName;
395
398
std::string name;
396
- currentValue () = Value (objectValue);
399
+ Value init (objectValue);
400
+ currentValue ().swapPayload (init);
397
401
currentValue ().setOffsetStart (tokenStart.start_ - begin_);
398
402
while (readToken (tokenName)) {
399
403
bool initialTokenOk = true ;
@@ -486,7 +490,7 @@ bool Reader::decodeNumber(Token& token) {
486
490
Value decoded;
487
491
if (!decodeNumber (token, decoded))
488
492
return false ;
489
- currentValue () = decoded;
493
+ currentValue (). swapPayload ( decoded) ;
490
494
currentValue ().setOffsetStart (token.start_ - begin_);
491
495
currentValue ().setOffsetLimit (token.end_ - begin_);
492
496
return true ;
Original file line number Diff line number Diff line change @@ -406,7 +406,7 @@ Value::~Value() {
406
406
}
407
407
408
408
Value& Value::operator =(Value other) {
409
- swapPayload (other);
409
+ swap (other);
410
410
return *this ;
411
411
}
412
412
You can’t perform that action at this time.
0 commit comments