mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-03-03 12:58:02 +01:00
Merge pull request #37 from BillyDonahue/value-efficiency
Switch to copy-and-swap idiom for operator=.
This commit is contained in:
commit
0dc03d0848
@ -171,7 +171,7 @@ private:
|
|||||||
CZString(const char *cstr, DuplicationPolicy allocate);
|
CZString(const char *cstr, DuplicationPolicy allocate);
|
||||||
CZString(const CZString &other);
|
CZString(const CZString &other);
|
||||||
~CZString();
|
~CZString();
|
||||||
CZString &operator=(const CZString &other);
|
CZString &operator=(CZString other);
|
||||||
bool operator<(const CZString &other) const;
|
bool operator<(const CZString &other) const;
|
||||||
bool operator==(const CZString &other) const;
|
bool operator==(const CZString &other) const;
|
||||||
ArrayIndex index() const;
|
ArrayIndex index() const;
|
||||||
@ -238,7 +238,7 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
Value(const Value &other);
|
Value(const Value &other);
|
||||||
~Value();
|
~Value();
|
||||||
|
|
||||||
Value &operator=(const Value &other);
|
Value &operator=(Value other);
|
||||||
/// Swap values.
|
/// Swap values.
|
||||||
/// \note Currently, comments are intentionally not swapped, for
|
/// \note Currently, comments are intentionally not swapped, for
|
||||||
/// both logic and efficiency.
|
/// both logic and efficiency.
|
||||||
@ -681,7 +681,7 @@ public:
|
|||||||
|
|
||||||
ValueInternalMap();
|
ValueInternalMap();
|
||||||
ValueInternalMap(const ValueInternalMap &other);
|
ValueInternalMap(const ValueInternalMap &other);
|
||||||
ValueInternalMap &operator=(const ValueInternalMap &other);
|
ValueInternalMap &operator=(ValueInternalMap other);
|
||||||
~ValueInternalMap();
|
~ValueInternalMap();
|
||||||
|
|
||||||
void swap(ValueInternalMap &other);
|
void swap(ValueInternalMap &other);
|
||||||
@ -775,7 +775,7 @@ public:
|
|||||||
|
|
||||||
ValueInternalArray();
|
ValueInternalArray();
|
||||||
ValueInternalArray(const ValueInternalArray &other);
|
ValueInternalArray(const ValueInternalArray &other);
|
||||||
ValueInternalArray &operator=(const ValueInternalArray &other);
|
ValueInternalArray &operator=(ValueInternalArray other);
|
||||||
~ValueInternalArray();
|
~ValueInternalArray();
|
||||||
void swap(ValueInternalArray &other);
|
void swap(ValueInternalArray &other);
|
||||||
|
|
||||||
|
@ -280,10 +280,9 @@ ValueInternalArray::ValueInternalArray( const ValueInternalArray &other )
|
|||||||
|
|
||||||
|
|
||||||
ValueInternalArray &
|
ValueInternalArray &
|
||||||
ValueInternalArray::operator =( const ValueInternalArray &other )
|
ValueInternalArray::operator=(ValueInternalArray other)
|
||||||
{
|
{
|
||||||
ValueInternalArray temp( other );
|
swap(other);
|
||||||
swap( temp );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,10 +196,9 @@ ValueInternalMap::ValueInternalMap( const ValueInternalMap &other )
|
|||||||
|
|
||||||
|
|
||||||
ValueInternalMap &
|
ValueInternalMap &
|
||||||
ValueInternalMap::operator =( const ValueInternalMap &other )
|
ValueInternalMap::operator=(ValueInternalMap other)
|
||||||
{
|
{
|
||||||
ValueInternalMap dummy( other );
|
swap(other);
|
||||||
swap( dummy );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,9 +190,8 @@ void Value::CZString::swap(CZString &other) {
|
|||||||
std::swap(index_, other.index_);
|
std::swap(index_, other.index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::CZString &Value::CZString::operator=(const CZString &other) {
|
Value::CZString &Value::CZString::operator=(CZString other) {
|
||||||
CZString temp(other);
|
swap(other);
|
||||||
swap(temp);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,9 +480,8 @@ Value::~Value() {
|
|||||||
delete[] comments_;
|
delete[] comments_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator=(const Value &other) {
|
Value &Value::operator=(Value other) {
|
||||||
Value temp(other);
|
swap(other);
|
||||||
swap(temp);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user