Make WordPress Core

Changeset 55757


Ignore:
Timestamp:
05/15/2023 10:26:54 AM (14 months ago)
Author:
SergeyBiryukov
Message:

General: Remove a few is_object() checks followed by instanceof operator.

This is a minor performance enhancement:

  • If an object is passed, the call to is_object() will be redundant.
  • If a non-object is passed, the instanceof operator (a variant of is_a()) will first check if it is an object before doing any further processing.

Therefore, no additional processing cycles should be wasted in both cases.

Follow-up to [6779], [48798], [48905], [49194], [55748].

Props Presskopp, costdev.
Fixes #58309.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-pclzip.php

    r51686 r55757  
    11711171    $this->privErrorReset();
    11721172
    1173     // ----- Look if the $p_archive is a PclZip object
    1174     if (is_object($p_archive) && $p_archive instanceof pclzip)
     1173    // ----- Look if the $p_archive is an instantiated PclZip object
     1174    if ($p_archive instanceof pclzip)
    11751175    {
    11761176
     
    12351235    }
    12361236
    1237     // ----- Look if the $p_archive_to_add is a PclZip object
    1238     if (is_object($p_archive_to_add) && $p_archive_to_add instanceof pclzip)
     1237    // ----- Look if the $p_archive_to_add is an instantiated PclZip object
     1238    if ($p_archive_to_add instanceof pclzip)
    12391239    {
    12401240
  • trunk/src/wp-includes/media.php

    r55703 r55757  
    37493749 *
    37503750 * In PHP 8.0, the GD extension uses GdImage objects for its data structures.
    3751  * This function checks if the passed value is either a resource of type `gd`
    3752  * or a GdImage object instance. Any other type will return false.
     3751 * This function checks if the passed value is either a GdImage object instance
     3752 * or a resource of type `gd`. Any other type will return false.
    37533753 *
    37543754 * @since 5.6.0
     
    37593759 */
    37603760function is_gd_image( $image ) {
    3761     if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
    3762         || is_object( $image ) && $image instanceof GdImage
     3761    if ( $image instanceof GdImage
     3762        || is_resource( $image ) && 'gd' === get_resource_type( $image )
    37633763    ) {
    37643764        return true;
Note: See TracChangeset for help on using the changeset viewer.