mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-14 23:07:55 +02:00
Switch to copy-and-swap idiom for operator=.
This allows the compiler to elide a copy when rhs is a temporary.
This commit is contained in:

committed by
Christopher Dunn

parent
236db83742
commit
45cd9490cd
@@ -280,10 +280,9 @@ ValueInternalArray::ValueInternalArray( const ValueInternalArray &other )
|
||||
|
||||
|
||||
ValueInternalArray &
|
||||
ValueInternalArray::operator =( const ValueInternalArray &other )
|
||||
ValueInternalArray::operator=(ValueInternalArray other)
|
||||
{
|
||||
ValueInternalArray temp( other );
|
||||
swap( temp );
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -196,10 +196,9 @@ ValueInternalMap::ValueInternalMap( const ValueInternalMap &other )
|
||||
|
||||
|
||||
ValueInternalMap &
|
||||
ValueInternalMap::operator =( const ValueInternalMap &other )
|
||||
ValueInternalMap::operator=(ValueInternalMap other)
|
||||
{
|
||||
ValueInternalMap dummy( other );
|
||||
swap( dummy );
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -190,9 +190,8 @@ void Value::CZString::swap(CZString &other) {
|
||||
std::swap(index_, other.index_);
|
||||
}
|
||||
|
||||
Value::CZString &Value::CZString::operator=(const CZString &other) {
|
||||
CZString temp(other);
|
||||
swap(temp);
|
||||
Value::CZString &Value::CZString::operator=(CZString other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -481,9 +480,8 @@ Value::~Value() {
|
||||
delete[] comments_;
|
||||
}
|
||||
|
||||
Value &Value::operator=(const Value &other) {
|
||||
Value temp(other);
|
||||
swap(temp);
|
||||
Value &Value::operator=(Value other) {
|
||||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user