Subject: | after $elt->cut_children, $elt->empty is false |
Date: | Fri, 12 Feb 2010 12:38:55 -0800 |
To: | bug-XML-Twig [...] rt.cpan.org |
From: | Andrew Pimlott <andrew [...] pimlott.net> |
Verified on Twig.pm 3.35. I'll cite the code in Twig_pm.slow.
$elt->cut_children calls $elt->cut on every element. When called on the
last element, the test at line 6410 is true:
if( $parent->_last_child == $elt) { $parent->set_last_child( $elt->_prev_sibling); }
$elt->_prev_sibling is of course undef at this point, but set_last_child
still assumes that calling it makes the element not empty:
sub set_last_child
{ $_[0]->set_not_empty;
On line 6408, there is a "fix-up" to set the element back to empty when
set_first_child was called with an undef value. The same thing could be
done for set_last_child.
I note, by the way, that your speedup script transforms the call to
set_first_child differently from the call to set_last_child. That is
curious to me, though I didn't look into why.
Andrew
--- Twig_pm.slow.orig 2010-02-12 20:35:30.000000000 +0000
+++ Twig_pm.slow 2010-02-12 20:34:04.000000000 +0000
@@ -6407,7 +6407,10 @@
{ $parent->set_first_child( $elt->_next_sibling);
unless( $elt->_next_sibling) { $parent->set_empty; }
}
- if( $parent->_last_child == $elt) { $parent->set_last_child( $elt->_prev_sibling); }
+ if( $parent->_last_child == $elt)
+ { $parent->set_last_child( $elt->_prev_sibling);
+ unless( $elt->{prev_sibling}) { $parent->{empty}= 1; }
+ }
if( $prev_sibling= $elt->_prev_sibling)
{ $prev_sibling->set_next_sibling( $elt->_next_sibling); }