1 對Json::Value的等號賦值都會引發原有值的變化,最終調用std::swap對值進行改變node
Value& Value::operator=(const Value& other) {
swap(const_cast<Value&>(other));
return *this;
}
ide
void Value::swapPayload(Value& other) {
ValueType temp = type_;
type_ = other.type_;
other.type_ = temp;
std::swap(value_, other.value_);
int temp2 = allocated_;
allocated_ = other.allocated_;
other.allocated_ = temp2 & 0x1;
}函數
因此當以下代碼執行的時候,將會node將會是空的性能
Json::Value node;this
root["node"] = node;spa
2 Json::Value的拷貝性能orm
Json::Value node = root[i];ci
這個函數方式將會對數據進行拷貝,影響性能,所以正確的作法是it
Json::Value& node = root[i];io