Commit 8895aa5a69 for wordpress.org
commit 8895aa5a6948f46caa8aff17433e79f08736c9c8
Author: Weston Ruter <weston@xwp.co>
Date: Mon Jan 12 21:17:00 2026 +0000
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.
Built from https://develop.svn.wordpress.org/trunk@61474
git-svn-id: http://core.svn.wordpress.org/trunk@60786 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/includes/class-wp-ms-themes-list-table.php b/wp-admin/includes/class-wp-ms-themes-list-table.php
index dd95834e91..37caa4b361 100644
--- a/wp-admin/includes/class-wp-ms-themes-list-table.php
+++ b/wp-admin/includes/class-wp-ms-themes-list-table.php
@@ -302,15 +302,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
$a = $theme_a[ $orderby ];
$b = $theme_b[ $orderby ];
- if ( $a === $b ) {
- return 0;
- }
-
- if ( 'DESC' === $order ) {
- return ( $a < $b ) ? 1 : -1;
- } else {
- return ( $a < $b ) ? -1 : 1;
- }
+ return 'DESC' === $order ?
+ $b <=> $a :
+ $a <=> $b;
}
/**
diff --git a/wp-admin/includes/class-wp-plugin-install-list-table.php b/wp-admin/includes/class-wp-plugin-install-list-table.php
index 1976dfa8ae..a029d725d7 100644
--- a/wp-admin/includes/class-wp-plugin-install-list-table.php
+++ b/wp-admin/includes/class-wp-plugin-install-list-table.php
@@ -458,15 +458,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$a = $plugin_a->$orderby;
$b = $plugin_b->$orderby;
- if ( $a === $b ) {
- return 0;
- }
-
- if ( 'DESC' === $this->order ) {
- return ( $a < $b ) ? 1 : -1;
- } else {
- return ( $a < $b ) ? -1 : 1;
- }
+ return 'DESC' === $this->order ?
+ $b <=> $a :
+ $a <=> $b;
}
/**
diff --git a/wp-admin/includes/menu.php b/wp-admin/includes/menu.php
index 3cf4a5fdd6..7b87e60604 100644
--- a/wp-admin/includes/menu.php
+++ b/wp-admin/includes/menu.php
@@ -327,12 +327,9 @@ if ( apply_filters( 'custom_menu_order', false ) ) {
} elseif ( ! isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
return 1;
} elseif ( isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
- if ( $menu_order[ $a ] === $menu_order[ $b ] ) {
- return 0;
- }
- return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1;
+ return $menu_order[ $a ] <=> $menu_order[ $b ];
} else {
- return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1;
+ return $default_menu_order[ $a ] <=> $default_menu_order[ $b ];
}
}
diff --git a/wp-includes/css/dist/index.php b/wp-includes/css/dist/index.php
index 7aee51e6f7..b256b1c4d9 100644
--- a/wp-includes/css/dist/index.php
+++ b/wp-includes/css/dist/index.php
@@ -8,13 +8,13 @@
return array(
array(
- 'handle' => 'wp-preferences',
- 'path' => 'preferences/style',
+ 'handle' => 'wp-nux',
+ 'path' => 'nux/style',
'dependencies' => array('wp-components'),
),
array(
- 'handle' => 'wp-nux',
- 'path' => 'nux/style',
+ 'handle' => 'wp-preferences',
+ 'path' => 'preferences/style',
'dependencies' => array('wp-components'),
),
array(
@@ -27,26 +27,26 @@ return array(
'path' => 'reusable-blocks/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
- array(
- 'handle' => 'wp-widgets',
- 'path' => 'widgets/style',
- 'dependencies' => array('wp-block-editor', 'wp-components'),
- ),
- array(
- 'handle' => 'wp-patterns',
- 'path' => 'patterns/style',
- 'dependencies' => array('wp-block-editor', 'wp-components'),
- ),
array(
'handle' => 'wp-commands',
'path' => 'commands/style',
'dependencies' => array('wp-components'),
),
+ array(
+ 'handle' => 'wp-widgets',
+ 'path' => 'widgets/style',
+ 'dependencies' => array('wp-block-editor', 'wp-components'),
+ ),
array(
'handle' => 'wp-components',
'path' => 'components/style',
'dependencies' => array(),
),
+ array(
+ 'handle' => 'wp-patterns',
+ 'path' => 'patterns/style',
+ 'dependencies' => array('wp-block-editor', 'wp-components'),
+ ),
array(
'handle' => 'wp-format-library',
'path' => 'format-library/style',
diff --git a/wp-includes/interactivity-api/class-wp-interactivity-api.php b/wp-includes/interactivity-api/class-wp-interactivity-api.php
index 539242e211..f2c66b07fc 100644
--- a/wp-includes/interactivity-api/class-wp-interactivity-api.php
+++ b/wp-includes/interactivity-api/class-wp-interactivity-api.php
@@ -904,14 +904,11 @@ final class WP_Interactivity_API {
$a_suffix = $a['suffix'] ?? '';
$b_suffix = $b['suffix'] ?? '';
if ( $a_suffix !== $b_suffix ) {
- return $a_suffix < $b_suffix ? -1 : 1;
+ return $a_suffix <=> $b_suffix;
}
$a_id = $a['unique_id'] ?? '';
$b_id = $b['unique_id'] ?? '';
- if ( $a_id === $b_id ) {
- return 0;
- }
- return $a_id > $b_id ? 1 : -1;
+ return $a_id <=> $b_id;
}
);
return $entries;
diff --git a/wp-includes/js/dist/script-modules/index.php b/wp-includes/js/dist/script-modules/index.php
index 6d7dc87dee..1438179747 100644
--- a/wp-includes/js/dist/script-modules/index.php
+++ b/wp-includes/js/dist/script-modules/index.php
@@ -7,11 +7,6 @@
*/
return array(
- array(
- 'id' => '@wordpress/interactivity',
- 'path' => 'interactivity/index',
- 'asset' => 'interactivity/index.min.asset.php',
- ),
array(
'id' => '@wordpress/interactivity-router',
'path' => 'interactivity-router/index',
@@ -22,6 +17,21 @@ return array(
'path' => 'interactivity-router/full-page',
'asset' => 'interactivity-router/full-page.min.asset.php',
),
+ array(
+ 'id' => '@wordpress/core-abilities',
+ 'path' => 'core-abilities/index',
+ 'asset' => 'core-abilities/index.min.asset.php',
+ ),
+ array(
+ 'id' => '@wordpress/interactivity',
+ 'path' => 'interactivity/index',
+ 'asset' => 'interactivity/index.min.asset.php',
+ ),
+ array(
+ 'id' => '@wordpress/abilities',
+ 'path' => 'abilities/index',
+ 'asset' => 'abilities/index.min.asset.php',
+ ),
array(
'id' => '@wordpress/a11y',
'path' => 'a11y/index',
@@ -38,25 +48,15 @@ return array(
'asset' => 'latex-to-mathml/loader.min.asset.php',
),
array(
- 'id' => '@wordpress/abilities',
- 'path' => 'abilities/index',
- 'asset' => 'abilities/index.min.asset.php',
- ),
- array(
- 'id' => '@wordpress/core-abilities',
- 'path' => 'core-abilities/index',
- 'asset' => 'core-abilities/index.min.asset.php',
+ 'id' => '@wordpress/edit-site-init',
+ 'path' => 'edit-site-init/index',
+ 'asset' => 'edit-site-init/index.min.asset.php',
),
array(
'id' => '@wordpress/route',
'path' => 'route/index',
'asset' => 'route/index.min.asset.php',
),
- array(
- 'id' => '@wordpress/edit-site-init',
- 'path' => 'edit-site-init/index',
- 'asset' => 'edit-site-init/index.min.asset.php',
- ),
array(
'id' => '@wordpress/lazy-editor',
'path' => 'lazy-editor/index',
diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php
index 32e3a70be1..8cd3301ff6 100644
--- a/wp-includes/script-loader.php
+++ b/wp-includes/script-loader.php
@@ -2999,7 +2999,7 @@ function wp_maybe_inline_styles() {
usort(
$styles,
static function ( $a, $b ) {
- return ( $a['size'] <= $b['size'] ) ? -1 : 1;
+ return $a['size'] <=> $b['size'];
}
);
diff --git a/wp-includes/version.php b/wp-includes/version.php
index cece6570dc..96a8b24508 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.0-alpha-61473';
+$wp_version = '7.0-alpha-61474';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.