Opened 6 years ago
Closed 6 years ago
#45553 closed enhancement (fixed)
Improve wp_is_stream() performance
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.1 | Priority: | low |
Severity: | minor | Version: | |
Component: | Filesystem API | Keywords: | has-patch |
Focuses: | Cc: |
Description
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:
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 );
}
A quick benchmark shows that this is around four times faster than the current method.
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.
In 44506: