Change the way references are counted to speedup cloning.
Before this patch, every time you cloned a formula, the clone visitor would recurse into the entire AST to increment the reference count of all nodes. When running ltl2tgba_fm on the formula generated by "LTLcounterLinear.pl 8", approx 27% of the time was spent in the clone visitor. After this patch, cloning a formula is just an increment of the reference count of the top node. Children are decremented only when the top node's ref count is decremented to zero. With this change, clone() and destroy() become constant time, the ltl2tgba_fm spend only 0.01% of the time cloning formulae. * src/ltlast/automatop.cc (~automatop): Decrement children. (instance): Decrement children if the instance already exists. * src/ltlast/binop.cc, src/ltlast/multop.cc, src/ltlast/unop.cc: Likewise. * src/ltlvisit/clone.cc (clone): Simplify, now we only need to call ref(). * src/ltlvisit/destroy.cc (destroy): Simplify, now we only need to call unref(). (destroy_visitor): Remove, no longer needed.
This commit is contained in:
parent
631f4b5bea
commit
8e4e692e7f
7 changed files with 74 additions and 32 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2003, 2009 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -93,9 +93,8 @@ namespace spot
|
|||
formula*
|
||||
clone(const formula* f)
|
||||
{
|
||||
clone_visitor v;
|
||||
const_cast<formula*>(f)->accept(v);
|
||||
return v.result();
|
||||
formula* res = const_cast<formula*>(f)->ref();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2003, 2004, 2009 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -25,24 +25,10 @@ namespace spot
|
|||
{
|
||||
namespace ltl
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class destroy_visitor: public postfix_visitor
|
||||
{
|
||||
public:
|
||||
virtual void
|
||||
doit_default(formula* c)
|
||||
{
|
||||
formula::unref(c);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
destroy(const formula* f)
|
||||
{
|
||||
destroy_visitor v;
|
||||
const_cast<formula*>(f)->accept(v);
|
||||
formula::unref(const_cast<formula*>(f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue