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

@ -588,21 +588,22 @@ namespace spot
pair p(op, v);
const multop* res;
// FIXME: Use lower_bound or hash_map.
map::iterator i = instances.find(p);
if (i != instances.end())
// Insert the key p with the dummy value 0 just
// to check if p already exists.
std::pair<map::iterator, bool> ires =
instances.insert(map::value_type(p, 0));
if (!ires.second)
{
// The instance already exists.
// The instance did already exists. Free v.
for (vec::iterator vi = v->begin(); vi != v->end(); ++vi)
(*vi)->destroy();
delete v;
res = i->second;
res = ires.first->second;
}
else
{
// This is the first instance of this formula.
// Record the instance in the map,
res = instances[p] = new multop(op, v);
// The instance did not already exist.
res = ires.first->second = new multop(op, v);
}
res->clone();
return res;