WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/19/2014 12:00:27 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Move preg_match() that should only run once out of the loop.

props dllh.
fixes #28575.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r28773 r28776  
    215215    $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
    216216
     217    $do_times_check = ( 1 === preg_match( '/(?<=\d)x-?\d/', $text ) );
     218
    217219    foreach ( $textarr as &$curl ) {
    218220        // Only call _wptexturize_pushpop_element if $curl is a delimeter.
     
    243245
    244246            // 9x9 (times), but never 0x9999
    245             if ( 1 === preg_match( '/(?<=\d)x-?\d/', $text ) ) {
     247            if ( $do_times_check ) {
    246248                // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
    247249                $curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(-?\d[\d\.,]*)\b/', '$1&#215;$2', $curl );
Note: See TracChangeset for help on using the changeset viewer.