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:
parent
2776de87da
commit
13c41ee773
6 changed files with 41 additions and 30 deletions
|
|
@ -102,13 +102,13 @@ namespace spot
|
|||
atomic_prop::instance(const std::string& name, environment& env)
|
||||
{
|
||||
pair p(name, &env);
|
||||
// FIXME: Use lower_bound, or a hash_map.
|
||||
map::iterator i = instances.find(p);
|
||||
const atomic_prop* ap;
|
||||
if (i != instances.end())
|
||||
ap = i->second;
|
||||
std::pair<map::iterator, bool> ires =
|
||||
instances.insert(map::value_type(p, 0));
|
||||
if (!ires.second)
|
||||
ap = ires.first->second;
|
||||
else
|
||||
ap = instances[p] = new atomic_prop(name, env);
|
||||
ap = ires.first->second = new atomic_prop(name, env);
|
||||
ap->clone();
|
||||
return ap;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,19 +95,20 @@ namespace spot
|
|||
{
|
||||
assert(nfa != 0);
|
||||
triplet p(std::make_pair(nfa, negated), v);
|
||||
map::iterator i = instances.find(p);
|
||||
const automatop* res;
|
||||
if (i != instances.end())
|
||||
std::pair<map::iterator, bool> ires =
|
||||
instances.insert(map::value_type(p, 0));
|
||||
if (!ires.second)
|
||||
{
|
||||
// The instance already exists.
|
||||
for (vec::iterator vi = v->begin(); vi != v->end(); ++vi)
|
||||
(*vi)->destroy();
|
||||
delete v;
|
||||
res = i->second;
|
||||
res = ires.first->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = instances[p] = new automatop(nfa, v, negated);
|
||||
res = ires.first->second = new automatop(nfa, v, negated);
|
||||
}
|
||||
res->clone();
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -262,14 +262,20 @@ namespace spot
|
|||
}
|
||||
|
||||
pair p(pairo(op, child), pairu(min, max));
|
||||
map::iterator i = instances.find(p);
|
||||
if (i != instances.end())
|
||||
|
||||
const formula* res;
|
||||
std::pair<map::iterator, bool> ires =
|
||||
instances.insert(map::value_type(p, 0));
|
||||
if (!ires.second)
|
||||
{
|
||||
// This instance already exists.
|
||||
child->destroy();
|
||||
return i->second->clone();
|
||||
res = ires.first->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = ires.first->second = new bunop(op, child, min, max);
|
||||
}
|
||||
const bunop* res = instances[p] = new bunop(op, child, min, max);
|
||||
res->clone();
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue