r23397 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23396‎ | r23397 | r23398 >
Date:16:50, 25 June 2007
Author:sanbeg
Status:old
Tags:
Comment:
Change preg_match_all(substr()) -> while(preg_match()) to save a long string copy. If only PHP had an upper limit on regex matches.
Modified paths:
  • /trunk/extensions/LabeledSectionTransclusion/lst.php (modified) (history)
  • /trunk/extensions/LabeledSectionTransclusion/lstParserTests.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/LabeledSectionTransclusion/lstParserTests.txt
@@ -267,7 +267,31 @@
268268 </p>
269269 !!end
270270
 271+!!article
 272+lst_head_bounds
 273+!!text
 274+===
 275+=2=
 276+<section begin=s/>
 277+=3=
 278+hi
 279+=4=
 280+<section end=s/>
 281+=head4=
 282+!!endarticle
 283+!!test
 284+more sensitive test for heading count boundaries.
 285+!!input
 286+{{#lst:lst_head_bounds|s}}
 287+!!result
 288+<a name="3"></a><h1><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Lst_head_bounds&amp;action=edit&amp;section=3" title="Lst head bounds">edit</a>]</span> <span class="mw-headline">3</span></h1>
 289+<p>hi
 290+</p>
 291+<a name="4"></a><h1><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Lst_head_bounds&amp;action=edit&amp;section=4" title="Lst head bounds">edit</a>]</span> <span class="mw-headline">4</span></h1>
271292
 293+!!end
 294+
 295+
272296 !!test
273297 Nick's bogus input
274298 !!input
Index: trunk/extensions/LabeledSectionTransclusion/lst.php
@@ -165,8 +165,21 @@
166166 */
167167 function wfLst_count_headings_($text,$limit)
168168 {
169 - $pat = '^(={1,6}).+\1\s*$';
170 - return preg_match_all( "/$pat/im", substr($text,0,$limit), $m);
 169+ $pat = '^(={1,6}).+\1\s*$()';
 170+
 171+ //return preg_match_all( "/$pat/im", substr($text,0,$limit), $m);
 172+
 173+ $count = 0;
 174+ $offset = 0;
 175+ while (preg_match("/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $offset)) {
 176+ if ($m[2][1] > $limit)
 177+ break;
 178+
 179+ $count++;
 180+ $offset = $m[2][1];
 181+ }
 182+
 183+ return $count;
171184 }
172185
173186 /**

Status & tagging log