[wp-trac] [WordPress Trac] #58587: Performance of in_array

WordPress Trac noreply at wordpress.org
Wed Jun 21 08:06:27 UTC 2023


#58587: Performance of in_array
-------------------------+-------------------------------------------
 Reporter:  benniledl    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  minor        |   Keywords:  has-testing-info dev-feedback
  Focuses:  performance  |
-------------------------+-------------------------------------------
 Hello,

 in get_site_transient in_array() is used to find whether a string is in an
 array or not. https://core.trac.wordpress.org/browser/tags/6.2/src/wp-
 includes/option.php#L1978

 I have written a small Test to see if in_array() is best for performance.
 https://github.com/benni1516/testing/blob/main/in_array

 In my tests I have found a faster way to get the same results. In my
 approach I save time by not needing to create an array and by using string
 comparison instead of in_array. I think this could be used in this
 function since the array is hardcoded anyway.

 I am a beginner and I want to learn by exploring WordPress, I am sorry if
 this ticket is nonsense. I am trying to learn how to properly approach
 developing in WordPress

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58587>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list