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.



git-svn-id: https://develop.svn.wordpress.org/trunk@44506 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-01-09 09:50:19 +00:00
parent f3b7b7f966
commit ba495ec173
1 changed files with 5 additions and 5 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 );
}
/**