[wp-trac] [WordPress Trac] #58069: Performance of _wp_normalize_relative_css_links() can be increased >2x

WordPress Trac noreply at wordpress.org
Wed Apr 19 23:19:40 UTC 2023


#58069: Performance of _wp_normalize_relative_css_links() can be increased >2x
-------------------------------------------------+-------------------------
 Reporter:  westonruter                          |       Owner:
                                                 |  westonruter
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.2.1
Component:  Script Loader                        |     Version:  5.9
 Severity:  normal                               |  Resolution:
 Keywords:  has-unit-tests fixed-major changes-  |     Focuses:  css,
  requested                                      |  performance
-------------------------------------------------+-------------------------
Changes (by azaozz):

 * keywords:  has-patch has-unit-tests fixed-major => has-unit-tests fixed-
     major changes-requested


Comment:

 Sorry, a nitpick :)

 The commit message says it "Improve code style and readability" but I tend
 to disagree. Both style and readability seem worse after the commit.

 Negating a long multi-line list of function calls wrapped in braces
 doesn't help readability. Better readability can be achieved by a short-
 circuit imho. I.e. something like:

 {{{
 if (
    str_starts_with( $url, 'http:' ) ||
    str_starts_with( $url, 'https:' ) ||
    str_starts_with( $url, '//' ) ||
    ....
 ) {
    return $prefix . $url;
 }

 $absolute_url = ...
 // etc.
 }}}

 Using (yet another) style for multi-line conditionals (every `||` on its
 own line) doesn't help it either. I know WPCS doesn't flag this as "error"
 but why should the style here be different than the rest of the WP code?

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


More information about the wp-trac mailing list