ltlast: use the return of insert() to avoid a double lookup

* src/ltlast/atomic_prop.cc, src/ltlast/automatop.cc,
src/ltlast/binop.cc, src/ltlast/bunop.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc: Do not look for a key
and then insert the (key,value) on failure.  Simply insert
(key,0), and replace 0 by value on failure.  This replaces two map
lookups by one.
This commit is contained in:
Alexandre Duret-Lutz 2012-12-19 17:37:13 +01:00
parent 2776de87da
commit 13c41ee773
6 changed files with 41 additions and 30 deletions

View file

@ -314,16 +314,18 @@ namespace spot
const unop* res;
pair p(op, child);
map::iterator i = instances.find(p);
if (i != instances.end())
std::pair<map::iterator, bool> ires =
instances.insert(map::value_type(p, 0));
if (!ires.second)
{
// This instance already exists.
child->destroy();
res = i->second;
res = ires.first->second;
}
else
{
res = instances[p] = new unop(op, child);
res = ires.first->second = new unop(op, child);
}
res->clone();
return res;