[wp-trac] [WordPress Trac] #64538: memoize wp_normalize_path

WordPress Trac noreply at wordpress.org
Fri Jan 23 17:42:05 UTC 2026


#64538: memoize wp_normalize_path
--------------------------------------+---------------------
 Reporter:  josephscott               |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  7.0
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by josephscott):

 @dmsnell I tested this version:

 {{{
 function wp_is_stream( $path ) {
         static $known_schemes = null;

         if ( null === $known_schemes ) {
                 $known_schemes = ' ';
                 foreach ( stream_get_wrappers() as $scheme ) {
                         $known_schemes .= "{$scheme} ";
                 }
         }

         // Valid protocol names must contain alphanumerics, dots (.),
 plusses (+), or hyphens (-) only.
         $protocol_length = strspn( $path,
 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.+-' );
         if ( 0 === $protocol_length || 0 !== substr_compare( $path, '://',
 $protocol_length, 3 ) ) {
                 return false;
         }

         $scheme = substr( $path, 0, $protocol_length );

         return str_contains( $known_schemes, " {$scheme} " );
 }
 }}}

 I didn't see any difference in the timing for `wp_normalize_path()` from
 the current code.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64538#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list