From: Tim Starling Date: Tue, 5 Jul 2016 10:32:44 +0000 (+1000) Subject: Balancer: Inline BalancerStack::length() X-Git-Tag: 1.31.0-rc.0~6388^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=7618d3be6818eb6fcb14194aefc9acc8944f8e8b;p=lhc%2Fweb%2Fwiklou.git Balancer: Inline BalancerStack::length() Provides 1% reduction in benchmark time Change-Id: Ie8ff66a836cd137234828effcce9547e2cb3cd58 --- diff --git a/includes/tidy/Balancer.php b/includes/tidy/Balancer.php index 6f7afffb71..9e96b14c60 100644 --- a/includes/tidy/Balancer.php +++ b/includes/tidy/Balancer.php @@ -813,7 +813,7 @@ class BalanceStack implements IteratorAggregate { $endTagSet = $thorough ? BalanceSets::$thoroughImpliedEndTagsSet : BalanceSets::$impliedEndTagsSet; - while ( $this->length() > 0 ) { + while ( $this->currentNode ) { if ( $butnot !== null && $this->currentNode->isHtmlNamed( $butnot ) ) { break; } @@ -828,7 +828,7 @@ class BalanceStack implements IteratorAggregate { * Return the adjusted current node. */ public function adjustedCurrentNode( $fragmentContext ) { - return ( $fragmentContext && $this->length() === 1 ) ? + return ( $fragmentContext && count( $this->elements ) === 1 ) ? $fragmentContext : $this->currentNode; } @@ -916,7 +916,8 @@ class BalanceStack implements IteratorAggregate { * @param int $idx */ public function popTo( $idx ) { - while ( $this->length() > $idx ) { + $length = count( $this->elements ); + for ( $length = count( $this->elements ); $length > $idx; $length-- ) { $this->pop(); } } @@ -928,7 +929,7 @@ class BalanceStack implements IteratorAggregate { * @param BalanceElement|array|string $tag */ public function popTag( $tag ) { - while ( $this->length() > 0 ) { + while ( $this->currentNode ) { if ( $this->currentNode->isA( $tag ) ) { $this->pop(); break; @@ -944,7 +945,7 @@ class BalanceStack implements IteratorAggregate { */ public function clearToContext( $set ) { // Note that we don't loop to 0. Never pop the elt off. - while ( $this->length() > 1 ) { + for ( $length = count( $this->elements ); $length > 1; $length-- ) { if ( $this->currentNode->isA( $set ) ) { break; }