From 80cc857fc1b835058b107692456a2f65ed6d6a79 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 6 Aug 2012 13:41:28 +0200 Subject: [PATCH] store text length in local var in Preprocess::processToObj/Xml The $text is constant and that means, the length of $text is also constant, store it in a local var is easy than. Change-Id: I9631b862f40eef7f8b18559ffd474a0037077d18 --- includes/parser/Preprocessor_DOM.php | 15 ++++++++------- includes/parser/Preprocessor_Hash.php | 15 ++++++++------- includes/parser/Preprocessor_HipHop.hphp | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 7fe420d8e6..e75237b41b 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -235,6 +235,7 @@ class Preprocessor_DOM implements Preprocessor { $searchBase = "[{<\n"; #} $revText = strrev( $text ); // For fast reverse searches + $lengthText = strlen( $text ); $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the start $accum =& $stack->getAccum(); # Current accumulator @@ -290,7 +291,7 @@ class Preprocessor_DOM implements Preprocessor { $accum .= htmlspecialchars( substr( $text, $i, $literalLength ) ); $i += $literalLength; } - if ( $i >= strlen( $text ) ) { + if ( $i >= $lengthText ) { if ( $currentClosing == "\n" ) { // Do a past-the-end run to finish off the heading $curChar = ''; @@ -354,10 +355,10 @@ class Preprocessor_DOM implements Preprocessor { // Unclosed comment in input, runs to end $inner = substr( $text, $i ); $accum .= '' . htmlspecialchars( $inner ) . ''; - $i = strlen( $text ); + $i = $lengthText; } else { // Search backwards for leading whitespace - $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0; + $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0; // Search forwards for trailing whitespace // $wsEnd will be the position of the last space (or the '>' if there's none) $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 ); @@ -438,7 +439,7 @@ class Preprocessor_DOM implements Preprocessor { } else { // No end tag -- let it run out to the end of the text. $inner = substr( $text, $tagEndPos + 1 ); - $i = strlen( $text ); + $i = $lengthText; $close = ''; } } @@ -498,16 +499,16 @@ class Preprocessor_DOM implements Preprocessor { $part = $piece->getCurrentPart(); // Search back through the input to see if it has a proper close // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient - $wsLength = strspn( $revText, " \t", strlen( $text ) - $i ); + $wsLength = strspn( $revText, " \t", $lengthText - $i ); $searchStart = $i - $wsLength; if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) { // Comment found at line end // Search for equals signs before the comment $searchStart = $part->visualEnd; - $searchStart -= strspn( $revText, " \t", strlen( $text ) - $searchStart ); + $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart ); } $count = $piece->count; - $equalsLength = strspn( $revText, '=', strlen( $text ) - $searchStart ); + $equalsLength = strspn( $revText, '=', $lengthText - $searchStart ); if ( $equalsLength > 0 ) { if ( $searchStart - $equalsLength == $piece->startPos ) { // This is just a single string of equals signs on its own line diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 0e202fd61b..630297adb5 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -177,6 +177,7 @@ class Preprocessor_Hash implements Preprocessor { $searchBase = "[{<\n"; $revText = strrev( $text ); // For fast reverse searches + $lengthText = strlen( $text ); $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the start $accum =& $stack->getAccum(); # Current accumulator @@ -231,7 +232,7 @@ class Preprocessor_Hash implements Preprocessor { $accum->addLiteral( substr( $text, $i, $literalLength ) ); $i += $literalLength; } - if ( $i >= strlen( $text ) ) { + if ( $i >= $lengthText ) { if ( $currentClosing == "\n" ) { // Do a past-the-end run to finish off the heading $curChar = ''; @@ -295,10 +296,10 @@ class Preprocessor_Hash implements Preprocessor { // Unclosed comment in input, runs to end $inner = substr( $text, $i ); $accum->addNodeWithText( 'comment', $inner ); - $i = strlen( $text ); + $i = $lengthText; } else { // Search backwards for leading whitespace - $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0; + $wsStart = $i ? ( $i - strspn( $revText, ' ', $lengthText - $i ) ) : 0; // Search forwards for trailing whitespace // $wsEnd will be the position of the last space (or the '>' if there's none) $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 ); @@ -383,7 +384,7 @@ class Preprocessor_Hash implements Preprocessor { } else { // No end tag -- let it run out to the end of the text. $inner = substr( $text, $tagEndPos + 1 ); - $i = strlen( $text ); + $i = $lengthText; $close = null; } } @@ -447,16 +448,16 @@ class Preprocessor_Hash implements Preprocessor { $part = $piece->getCurrentPart(); // Search back through the input to see if it has a proper close // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient - $wsLength = strspn( $revText, " \t", strlen( $text ) - $i ); + $wsLength = strspn( $revText, " \t", $lengthText - $i ); $searchStart = $i - $wsLength; if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) { // Comment found at line end // Search for equals signs before the comment $searchStart = $part->visualEnd; - $searchStart -= strspn( $revText, " \t", strlen( $text ) - $searchStart ); + $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart ); } $count = $piece->count; - $equalsLength = strspn( $revText, '=', strlen( $text ) - $searchStart ); + $equalsLength = strspn( $revText, '=', $lengthText - $searchStart ); if ( $equalsLength > 0 ) { if ( $searchStart - $equalsLength == $piece->startPos ) { // This is just a single string of equals signs on its own line diff --git a/includes/parser/Preprocessor_HipHop.hphp b/includes/parser/Preprocessor_HipHop.hphp index d7b07162d6..fb4a8c7e75 100644 --- a/includes/parser/Preprocessor_HipHop.hphp +++ b/includes/parser/Preprocessor_HipHop.hphp @@ -115,7 +115,9 @@ class Preprocessor_HipHop implements Preprocessor { // Check cache. global $wgMemc, $wgPreprocessorCacheThreshold; - $cacheable = ($wgPreprocessorCacheThreshold !== false && strlen( $text ) > $wgPreprocessorCacheThreshold); + $lengthText = strlen( $text ); + + $cacheable = ($wgPreprocessorCacheThreshold !== false && $lengthText > $wgPreprocessorCacheThreshold); if ( $cacheable ) { wfProfileIn( __METHOD__.'-cacheable' ); @@ -239,7 +241,7 @@ class Preprocessor_HipHop implements Preprocessor { $accum->addLiteral( strval( substr( $text, $i, $literalLength ) ) ); $i += $literalLength; } - if ( $i >= strlen( $text ) ) { + if ( $i >= $lengthText ) { if ( $currentClosing === "\n" ) { // Do a past-the-end run to finish off the heading $curChar = ''; @@ -305,12 +307,12 @@ class Preprocessor_HipHop implements Preprocessor { // Unclosed comment in input, runs to end $inner = strval( substr( $text, $i ) ); $accum->addNodeWithText( 'comment', $inner ); - $i = strlen( $text ); + $i = $lengthText; } else { $endPos = intval( $variantEndPos ); // Search backwards for leading whitespace if ( $i ) { - $wsStart = $i - intval( strspn( $revText, ' ', strlen( $text ) - $i ) ); + $wsStart = $i - intval( strspn( $revText, ' ', $lengthText - $i ) ); } else { $wsStart = 0; } @@ -403,7 +405,7 @@ class Preprocessor_HipHop implements Preprocessor { } else { // No end tag -- let it run out to the end of the text. $inner = strval( substr( $text, $tagEndPos + 1 ) ); - $i = strlen( $text ); + $i = $lengthText; $haveClose = false; } } @@ -468,16 +470,16 @@ class Preprocessor_HipHop implements Preprocessor { $part = $piece->getCurrentPart(); // Search back through the input to see if it has a proper close // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient - $wsLength = intval( strspn( $revText, " \t", strlen( $text ) - $i ) ); + $wsLength = intval( strspn( $revText, " \t", $lengthText - $i ) ); $searchStart = $i - $wsLength; if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) { // Comment found at line end // Search for equals signs before the comment $searchStart = intval( $part->visualEnd ); - $searchStart -= intval( strspn( $revText, " \t", strlen( $text ) - $searchStart ) ); + $searchStart -= intval( strspn( $revText, " \t", $lengthText - $searchStart ) ); } $count = intval( $piece->count ); - $equalsLength = intval( strspn( $revText, '=', strlen( $text ) - $searchStart ) ); + $equalsLength = intval( strspn( $revText, '=', $lengthText - $searchStart ) ); $isTreeNode = false; $resultAccum = $accum; if ( $equalsLength > 0 ) { -- 2.20.1