From 9f25ea37c7819e9e6768ba9d647021da7280fc4d Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 9 Jan 2019 09:51:54 +0000 Subject: [PATCH] Filesystem: Improve `wp_is_stream()` performance. Instead of turning the return value of `stream_get_wrappers()` into a regex to match the scheme, we can instead extract the scheme and search the return value of `stream_get_wrappers()`. Props schlessera, swissspidy. Fixes #45553. Built from https://develop.svn.wordpress.org/trunk@44506 git-svn-id: http://core.svn.wordpress.org/trunk@44337 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 10 +++++----- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 9a8b4cf911..39de1470e2 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -5706,16 +5706,16 @@ function _device_can_upload() { * @return bool True if the path is a stream URL. */ function wp_is_stream( $path ) { - if ( false === strpos( $path, '://' ) ) { + $scheme_separator = strpos( $path, '://' ); + + if ( false === $scheme_separator ) { // $path isn't a stream return false; } - $wrappers = stream_get_wrappers(); - $wrappers = array_map( 'preg_quote', $wrappers ); - $wrappers_re = '(' . join( '|', $wrappers ) . ')'; + $stream = substr( $path, 0, $scheme_separator ); - return preg_match( "!^$wrappers_re://!", $path ) === 1; + return in_array( $stream, stream_get_wrappers(), true ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 0ad528530c..847d505711 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44505'; +$wp_version = '5.1-alpha-44506'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.