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