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

@ -525,19 +525,20 @@ namespace spot
pairf pf(first, second);
pair p(op, pf);
// FIXME: Use lower_bound or hash_map.
map::iterator i = instances.find(p);
const binop* res;
if (i != instances.end())
std::pair<map::iterator, bool> ires =
instances.insert(map::value_type(p, 0));
if (!ires.second)
{
// This instance already exists.
first->destroy();
second->destroy();
res = i->second;
res = ires.first->second;
}
else
{
res = instances[p] = new binop(op, first, second);
res = ires.first->second = new binop(op, first, second);
}
res->clone();
return res;