From: Jan T. <de...@us...> - 2002-05-09 19:09:44
|
Update of /cvsroot/net-script/netscript2/src/perl/XML/DOM2 In directory usw-pr-cvs1:/tmp/cvs-serv25263 Modified Files: CharacterData.pm Node.pm NodeList.pm Log Message: * lots of optimization Index: CharacterData.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/CharacterData.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CharacterData.pm 17 Mar 2002 19:26:14 -0000 1.4 --- CharacterData.pm 9 May 2002 19:09:41 -0000 1.5 *************** *** 56,61 **** if ( defined( $paramsRef ) ) { ! my %params = %{$paramsRef}; ! $this -> { m_data } = $params{"data"}; } --- 56,60 ---- if ( defined( $paramsRef ) ) { ! $this -> { m_data } = $paramsRef -> {"data"}; } Index: Node.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/Node.pm,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Node.pm 26 Apr 2002 10:50:52 -0000 1.15 --- Node.pm 9 May 2002 19:09:41 -0000 1.16 *************** *** 59,63 **** bless( $this, $class ); # create Object ! $this -> { m_childNodes } = XML::DOM2::NodeList -> new (); $this -> { m_ownerDocument } = undef; $this -> { m_parentNode } = undef; --- 59,63 ---- bless( $this, $class ); # create Object ! $this -> { m_childNodes } = undef; # XML::DOM2::NodeList -> new (); #LAZY $this -> { m_ownerDocument } = undef; $this -> { m_parentNode } = undef; *************** *** 69,72 **** --- 69,74 ---- $this -> { m_readOnly } = 0; $this -> { m_nodeName } = undef; + $this -> { m_firstChild } = undef; + $this -> { m_lastChild } = undef; return $this; # return Object } *************** *** 96,100 **** sub childNodes { my ( $this ) = @_; ! return $this -> { m_childNodes }; } --- 98,105 ---- sub childNodes { my ( $this ) = @_; ! unless( defined( $this -> { m_childNodes } ) ) { ! $this -> { m_childNodes } = XML::DOM2::NodeList -> new(); ! } ! $this -> { m_childNodes }; } *************** *** 111,120 **** my ( $this ) = @_; ! if ( $this -> childNodes() -> length() > 0 ) { ! return $this -> childNodes() -> item( { index => 0 } ) ; ! } ! else { ! return undef; ! } } --- 116,126 ---- my ( $this ) = @_; ! $this -> { m_firstChild }; ! # if ( $this -> childNodes() -> length() > 0 ) { ! # return $this -> childNodes() -> item( { index => 0 } ) ; ! # } ! # else { ! # return undef; ! # } } *************** *** 129,141 **** sub lastChild { my ( $this ) = @_; ! ! my $len = $this -> childNodes() -> length(); ! ! if ( $len > 0 ) { ! return $this -> childNodes() -> item( { index => $len - 1 } ) ; ! } ! else { ! return undef; ! } } --- 135,148 ---- sub lastChild { my ( $this ) = @_; ! ! $this -> { m_lastChild }; ! # my $len = $this -> childNodes() -> length(); ! # ! # if ( $len > 0 ) { ! # return $this -> childNodes() -> item( { index => $len - 1 } ) ; ! # } ! # else { ! # return undef; ! # } } *************** *** 397,400 **** --- 404,411 ---- # add node to children $this -> childNodes() -> add( { node => $newNode } ); + # new node is last child + $this -> { m_lastChild } = $newNode; + # new node is first child if there was no node before + $this -> { m_firstChild } = $newNode unless( defined($lastChild) ); # set new parent $newNode -> { m_parentNode } = $this; *************** *** 551,555 **** $newNode -> { m_nextSibling } = $refNode; $refNode -> { m_previousSibling } = $newNode; ! $newNode; } --- 562,571 ---- $newNode -> { m_nextSibling } = $refNode; $refNode -> { m_previousSibling } = $newNode; ! ! # if node was inserted before the first child it is now hte first child ! if ( $refNode == $this -> firstChild() ) { ! $this -> { m_firstChild } = $newNode; ! } ! # lastchild is not changed by this sub $newNode; } *************** *** 630,636 **** --- 646,664 ---- } + # if we remove the last child, its predecessor will become + # the last child + if ( $oldChild == $this -> lastChild() ) { + $this -> { m_lastChild } = $oldChild -> previousSibling(); + } + # if we remove the first child, its successor will become the + # first child + if ( $oldChild == $this -> firstChild() ) { + $this -> { m_firstChild } = $oldChild -> nextSibling(); + } + $this -> childNodes() -> remove( { index => $index } ); $oldChild -> { m_parentNode } = undef; + # get siblings right $oldChild -> nextSibling() -> { m_previousSibling } = *************** *** 748,754 **** my $aNode = $params{ aNode }; if ( $aNode == $this ) { return 1; ! } else { my $parent = $this -> parentNode(); --- 776,788 ---- my $aNode = $params{ aNode }; + # if the given node has no children it cannot be the ancestor + # of this node, so we can return false in a quick way + unless ( $aNode -> hasChildNodes() ) { + return 0; + } + if ( $aNode == $this ) { return 1; ! } else { my $parent = $this -> parentNode(); Index: NodeList.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/NodeList.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NodeList.pm 26 Apr 2002 10:50:52 -0000 1.10 --- NodeList.pm 9 May 2002 19:09:41 -0000 1.11 *************** *** 44,47 **** --- 44,48 ---- $this -> { m_nodeList } = \@nodeList; + $this -> { m_length } = 0; return $this; # return Object } *************** *** 59,63 **** my $index = $paramsRef -> { 'index' }; ! if ( $index < 0 || $index > $this -> length() ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), --- 60,64 ---- my $index = $paramsRef -> { 'index' }; ! if ( $index < 0 || $index >= $this -> { m_length } ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), *************** *** 81,85 **** sub length { my ( $this ) = @_; ! scalar @{ $this -> { m_nodeList } }; } --- 82,86 ---- sub length { my ( $this ) = @_; ! $this -> { m_length }; } *************** *** 96,99 **** --- 97,101 ---- my $node = $paramsRef -> { node }; push (@{ $this -> { m_nodeList } }, $node ); + $this -> { m_length }++; } *************** *** 111,115 **** my $index = $paramsRef -> { 'index' }; ! if ( $index < 0 || $index > $this -> length() ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), --- 113,117 ---- my $index = $paramsRef -> { 'index' }; ! if ( $index < 0 || $index >= $this -> { m_length } ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), *************** *** 124,128 **** my $node = $this -> item({ index => $index }); splice( @{ $this -> { m_nodeList } }, $index, 1 ); ! return $node; } --- 126,131 ---- my $node = $this -> item({ index => $index }); splice( @{ $this -> { m_nodeList } }, $index, 1 ); ! $this -> { m_length }--; ! $node; } *************** *** 142,146 **** my $index = $paramsRef -> { 'index' }; my $node = $paramsRef -> { node }; ! if ( $index < 0 || $index => $this -> length() ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), --- 145,149 ---- my $index = $paramsRef -> { 'index' }; my $node = $paramsRef -> { node }; ! if ( $index < 0 || $index >= $this -> { m_length } ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), *************** *** 153,156 **** --- 156,160 ---- } splice( @{ $this -> { m_nodeList } }, $index, 0, $node ); + $this -> { m_length }++; } *************** *** 197,199 **** --- 201,204 ---- my @emptyList = (); $this -> { m_nodeList } = \@emptyList; + $this -> { m_length } = 0; } |