Make WordPress Core


Ignore:
Timestamp:
01/12/2026 09:15:00 PM (7 months ago)
Author:
westonruter
Message:

Code Modernization: Utilize spaceship operator <=> in sort comparison logic.

Some replaced instances also fix a bug where the comparison function should have returned 0 as opposed to 1 or -1 as used in ternaries. This results in a performance improvement.

Developed in https://github.com/WordPress/wordpress-develop/pull/10717

Props soean, mukesh27, westonruter.
Fixes #64497.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php

    r61197 r61474  
    905905                                $b_suffix = $b['suffix'] ?? '';
    906906                                if ( $a_suffix !== $b_suffix ) {
    907                                         return $a_suffix < $b_suffix ? -1 : 1;
     907                                        return $a_suffix <=> $b_suffix;
    908908                                }
    909909                                $a_id = $a['unique_id'] ?? '';
    910910                                $b_id = $b['unique_id'] ?? '';
    911                                 if ( $a_id === $b_id ) {
    912                                         return 0;
    913                                 }
    914                                 return $a_id > $b_id ? 1 : -1;
     911                                return $a_id <=> $b_id;
    915912                        }
    916913                );
Note: See TracChangeset for help on using the changeset viewer.