Commit 15c2a947 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Small speedup in safra_tree::compare().

* src/tgba/tgbasafracomplement.cc (safra_tree::compare): Improve
the order of the tests.
parent a9669d3d
2012-01-18 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Small speedup in safra_tree::compare().
* src/tgba/tgbasafracomplement.cc (safra_tree::compare): Improve
the order of the tests.
2012-01-18 Alexandre Duret-Lutz <adl@lrde.epita.fr>
* NEWS: Mention the last two changes.
......
......@@ -197,39 +197,34 @@ namespace spot
/// a signed value.
int safra_tree::compare(const safra_tree* other) const
{
int subset_compare = 0;
subset_t::const_iterator in1 = nodes.begin();
subset_t::const_iterator in2 = other->nodes.begin();
int res = name - other->name;
if (res != 0)
return res;
if (nodes.size() != other->nodes.size())
return (nodes.size() - other->nodes.size());
if (marked != other->marked)
return (marked) ? -1 : 1;
if (name != other->name)
return name - other->name;
res = nodes.size() - other->nodes.size();
if (res != 0)
return res;
for (; in1 != nodes.end() && in2 != other->nodes.end(); ++in1, ++in2)
if ((subset_compare = (*in1)->compare(*in2)) != 0)
break;
res = children.size() - other->children.size();
if (res != 0)
return res;
if (subset_compare != 0)
return subset_compare;
// Call compare() only as a last resort, because it takes time.
subset_t::const_iterator in1 = nodes.begin();
subset_t::const_iterator in2 = other->nodes.begin();
for (; in1 != nodes.end(); ++in1, ++in2)
if ((res = (*in1)->compare(*in2)) != 0)
return res;
child_list::const_iterator ic1 = children.begin();
child_list::const_iterator ic2 = other->children.begin();
if (children.size() != other->children.size())
return (children.size() - other->children.size());
for (; ic1 != children.end() && ic2 != other->children.end();
++ic1, ++ic2)
{
int compare_value = (*ic1)->compare(*ic2);
if (compare_value != 0)
return compare_value;
}
if (marked != other->marked)
return (marked) ? -1 : 1;
for (; ic1 != children.end(); ++ic1, ++ic2)
if ((res = (*ic1)->compare(*ic2)) != 0)
return res;
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment