From 38eafdce8a32e1426bda30c55fc85ed21731292b Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 4 Jan 2007 21:56:37 +0000 Subject: [PATCH] Improve Parser::strip() performance by delaying update of the strip state until the end of the parse. This improves performance in two ways: firstly by minimising the size of the state array in the case of large numbers of tags, and secondly by avoiding unnecessary invalidation of the FSS object, when FSS is enabled. The same function is preserved, because a placeholder from one recursion level should never find its way into the output of the same recursion level. --- includes/Parser.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 7b480eb56a..6fd56ed17c 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -537,6 +537,8 @@ class Parser $uniq_prefix = $this->mUniqPrefix; $commentState = new ReplacementArray; + $nowikiItems = array(); + $generalItems = array(); $elements = array_merge( array( 'nowiki', 'gallery' ), @@ -603,18 +605,22 @@ class Parser $output = $tag; } - // Unstrip the output, because unstrip() is no longer recursive so - // it won't do it itself + // Unstrip the output, to support recursive strip() calls $output = $state->unstripBoth( $output ); if( !$stripcomments && $element == '!--' ) { $commentState->setPair( $marker, $output ); } elseif ( $element == 'html' || $element == 'nowiki' ) { - $state->nowiki->setPair( $marker, $output ); + $nowikiItems[$marker] = $output; } else { - $state->general->setPair( $marker, $output ); + $generalItems[$marker] = $output; } } + # Add the new items to the state + # We do this after the loop instead of during it to avoid slowing + # down the recursive unstrip + $state->nowiki->mergeArray( $nowikiItems ); + $state->general->mergeArray( $generalItems ); # Unstrip comments unless explicitly told otherwise. # (The comments are always stripped prior to this point, so as to -- 2.20.1