mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-01-31 14:39:52 +01:00
Merge pull request #118 from datadiode/47_fix_value_swap
swap comments too * Changed `operator=` to exclude start/limit, which should never have been added. * Changed `swap` to include comments. Hmm. That affects efficiency (but *not* for `operator=`) and probably nothing else in practice. - issue #47
This commit is contained in:
commit
55db3c3cb2
@ -240,8 +240,6 @@ Json::Value obj_value(Json::objectValue); // {}
|
||||
|
||||
Value& operator=(Value other);
|
||||
/// Swap values.
|
||||
/// \note Currently, comments are intentionally not swapped, for
|
||||
/// both logic and efficiency.
|
||||
void swap(Value& other);
|
||||
|
||||
ValueType type() const;
|
||||
@ -444,6 +442,9 @@ private:
|
||||
|
||||
Value& resolveReference(const char* key, bool isStatic);
|
||||
|
||||
/// Swap values but leave comments and source offsets in place.
|
||||
void swapPayload(Value& other);
|
||||
|
||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
inline bool isItemAvailable() const { return itemIsUsed_ == 0; }
|
||||
|
||||
|
@ -406,11 +406,11 @@ Value::~Value() {
|
||||
}
|
||||
|
||||
Value& Value::operator=(Value other) {
|
||||
swap(other);
|
||||
swapPayload(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Value::swap(Value& other) {
|
||||
void Value::swapPayload(Value& other) {
|
||||
ValueType temp = type_;
|
||||
type_ = other.type_;
|
||||
other.type_ = temp;
|
||||
@ -418,6 +418,11 @@ void Value::swap(Value& other) {
|
||||
int temp2 = allocated_;
|
||||
allocated_ = other.allocated_;
|
||||
other.allocated_ = temp2;
|
||||
}
|
||||
|
||||
void Value::swap(Value& other) {
|
||||
swapPayload(other);
|
||||
std::swap(comments_, other.comments_);
|
||||
std::swap(start_, other.start_);
|
||||
std::swap(limit_, other.limit_);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user