Skip to content

Commit c07ef37

Browse files
author
datadiode
committed
https://github.com/open-source-parsers/jsoncpp/issues/47
1 parent 62ab94d commit c07ef37

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/json/value.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ Json::Value obj_value(Json::objectValue); // {}
240240

241241
Value& operator=(Value other);
242242
/// Swap values.
243-
/// \note Currently, comments are intentionally not swapped, for
244-
/// both logic and efficiency.
245243
void swap(Value& other);
246244

247245
ValueType type() const;
@@ -444,6 +442,9 @@ Json::Value obj_value(Json::objectValue); // {}
444442

445443
Value& resolveReference(const char* key, bool isStatic);
446444

445+
/// Swap values but leave comments and source offsets in place.
446+
void swapPayload(Value& other);
447+
447448
#ifdef JSON_VALUE_USE_INTERNAL_MAP
448449
inline bool isItemAvailable() const { return itemIsUsed_ == 0; }
449450

src/lib_json/json_value.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,23 @@ Value::~Value() {
406406
}
407407

408408
Value& Value::operator=(Value other) {
409-
swap(other);
409+
swapPayload(other);
410410
return *this;
411411
}
412412

413-
void Value::swap(Value& other) {
413+
void Value::swapPayload(Value& other) {
414414
ValueType temp = type_;
415415
type_ = other.type_;
416416
other.type_ = temp;
417417
std::swap(value_, other.value_);
418418
int temp2 = allocated_;
419419
allocated_ = other.allocated_;
420420
other.allocated_ = temp2;
421+
}
422+
423+
void Value::swap(Value& other) {
424+
swapPayload(other);
425+
std::swap(comments_, other.comments_);
421426
std::swap(start_, other.start_);
422427
std::swap(limit_, other.limit_);
423428
}

0 commit comments

Comments
 (0)