r24579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24578‎ | r24579 | r24580 >
Date:13:54, 4 August 2007
Author:robchurch
Status:old
Tags:
Comment:
getBoxOption() speed-up: Parse all options in one go and thereafter do a simple lookup
Modified paths:
  • /trunk/extensions/inputbox/inputbox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/inputbox/inputbox.php
@@ -73,15 +73,22 @@
7474 }
7575
7676
77 -function getBoxOption(&$value,&$input,$name,$isNumber=false) {
78 -
79 - if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
80 - if($isNumber) {
81 - $value=intval($matches[1]);
82 - } else {
83 - $value=htmlspecialchars($matches[1]);
84 - }
 77+function getBoxOption( &$value, $input, $name, $isNumber = false ) {
 78+ static $values = false;
 79+ wfProfileIn( __METHOD__ );
 80+ if( $values === false ) {
 81+ $values = array();
 82+ $lines = explode( "\n", $input );
 83+ foreach( $lines as $line ) {
 84+ if( strpos( $line, '=' ) === false )
 85+ continue;
 86+ list( $lname, $lval ) = explode( '=', $line, 2 );
 87+ $values[ strtolower( trim( $lname ) ) ] = trim( $lval );
 88+ }
8589 }
 90+ if( isset( $values[$name] ) )
 91+ $value = $isNumber ? intval( $values[$name] ) : htmlspecialchars( $values[$name] );
 92+ wfProfileOut( __METHOD__ );
8693 }
8794
8895 class Inputbox {

Status & tagging log