Make WordPress Core

Changeset 44554


Ignore:
Timestamp:
01/10/2019 11:19:37 PM (6 years ago)
Author:
pento
Message:

Emoji: Improve performance when encoding or staticizing emoji.

Both wp_encode_emoji() and wp_staticize_emoji() perform a PHP version check when deciding how to apply their behaviour, but this check only needs to happen once, rather than every time in their internal looks.

Moving the check outside of the loop reduces processing time by 50%.

Props johnbillion.
Fixes #45930.

File:
1 edited

Legend:

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

    r44261 r44554  
    54785478function wp_encode_emoji( $content ) {
    54795479    $emoji = _wp_emoji_list( 'partials' );
     5480    $compat = version_compare( phpversion(), '5.4', '<' );
    54805481
    54815482    foreach ( $emoji as $emojum ) {
    5482         if ( version_compare( phpversion(), '5.4', '<' ) ) {
     5483        if ( $compat ) {
    54835484            $emoji_char = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
    54845485        } else {
     
    55205521    // Quickly narrow down the list of emoji that might be in the text and need replacing.
    55215522    $possible_emoji = array();
     5523    $compat         = version_compare( phpversion(), '5.4', '<' );
    55225524    foreach ( $emoji as $emojum ) {
    55235525        if ( false !== strpos( $text, $emojum ) ) {
    5524             if ( version_compare( phpversion(), '5.4', '<' ) ) {
     5526            if ( $compat ) {
    55255527                $possible_emoji[ $emojum ] = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
    55265528            } else {
Note: See TracChangeset for help on using the changeset viewer.