[wp-trac] [WordPress Trac] #45553: Improve wp_is_stream() performance
WordPress Trac
noreply at wordpress.org
Sun Dec 9 16:48:05 UTC 2018
#45553: Improve wp_is_stream() performance
----------------------------+-----------------------
Reporter: swissspidy | Owner: (none)
Type: enhancement | Status: new
Priority: low | Milestone: 5.1
Component: Filesystem API | Version:
Severity: minor | Keywords: has-patch
Focuses: |
----------------------------+-----------------------
The `wp_is_stream()` function (used by functions like
`wp_normalize_path()` currently uses a dynamically constructed regex to
detect streams. This could be verified a lot by using `in_array()`
instead.
@schlessera suggested the following version over at https://github.com/wp-
cli/wp-cli/issues/5008:
{{{#!php
function wp_is_stream( $path ) {
$scheme_separator = strpos( $path, '://' );
if ( false === $scheme_separator ) {
// $path isn't a stream
return false;
}
$stream = substr( $path, 0, $scheme_separator );
return in_array( $stream, stream_get_wrappers(), true );
}
}}}
[https://3v4l.org/BTHk0 A quick benchmark] shows that this is around four
times faster than the current method.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45553>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list