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
This commit is contained in:
Gary Pendergast 2019-01-09 09:51:54 +00:00
parent 184c501d5c
commit 9f25ea37c7
2 changed files with 6 additions and 6 deletions

View File

@ -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 );
}
/**

View File

@ -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.