I am still shocked after discovering a mysterious problem in our project.
We realized that calling HasMember ("string") performed an additional search. So, for performance reasons, we are changing it.
Main idea:
Instead of calling HasMember and subsequently chasing the link, for example:
rapidjson::Document d;
d.Parse<0>(json);
if(d.HasMember("foo"))
{
const rapidjson::Value& fooValue = d["foo"];
}
Changed to:
rapidjson::Document d;
d.Parse<0>(json);
const rapidjson::Value& fooValue = d["foo"];
if( !fooValue.IsNull() )
{
}
It was very good, we save to execute two requests instead of one. However, there is a problem.
If you start watching how quickjson implements nullvalue (returns by default if the search fails), you will see the following code:
GenericValue & operator[](const Ch* name) {
if (Member * member = FindMember(name)) {
return member->value;
} else {
static GenericValue NullValue;
return NullValue;
}
}
const GenericValue & operator[] (const Ch* name) const {
return const_cast<GenericValue &> (* this)[name];
}
, , . , , .
, - NullValue. , IsNull ( ) , NullValue .
, ? , ?
, null , const, . const, const_cast ( , , ).
, . - quickjson, .