[wp-trac] [WordPress Trac] #56804: More readable and faster check for array of arrays in register_rest_route()

WordPress Trac noreply at wordpress.org
Fri Oct 14 15:53:48 UTC 2022


#56804: More readable and faster check for array of arrays in register_rest_route()
------------------------------+-----------------------------
 Reporter:  TobiasBg          |       Owner:  SergeyBiryukov
     Type:  enhancement       |      Status:  closed
 Priority:  normal            |   Milestone:  6.1
Component:  REST API          |     Version:  trunk
 Severity:  normal            |  Resolution:  fixed
 Keywords:  has-patch commit  |     Focuses:  performance
------------------------------+-----------------------------
Changes (by SergeyBiryukov):

 * owner:  (none) => SergeyBiryukov
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"54518" 54518]:
 {{{
 #!CommitTicketReference repository="" revision="54518"
 REST API: Simplify the check for an array of arrays in
 `register_rest_route()`.

 The previous implementation of checking whether the `args` parameter is an
 array of arrays used `array_filter()`, which would always loop the full
 array, even though we are only interested in finding one (the first) non-
 array to display a `_doing_it_wrong()` message.

 This commit aims to improve readability and performance of this check by
 using a `foreach` loop instead, leaving it as soon as the first non-array
 argument is found.

 Follow-up to [54339].

 Props TobiasBg, audrasjb, costdev, SergeyBiryukov.
 Fixes #56804.
 }}}

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


More information about the wp-trac mailing list