Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#17754 closed enhancement (fixed)

preg_match() use is overkill in path_is_absolute()

Reported by: coffee2code's profile coffee2code Owned by: duck_'s profile duck_
Milestone: 3.3 Priority: normal
Severity: minor Version: 3.1.4
Component: Performance Keywords: has-patch
Focuses: Cc:


path_is_absolute() utilizes preg_match() to check if the first character of a path string is either of two possibilities. This is way overkill for such a simple case. The alternative I've proposed via the attached patch is more performant and makes the intention of the code clearer (rather than obscured in a regular expression).

Attachments (2)

17754.diff (414 bytes) - added by coffee2code 13 years ago.
17754.2.diff (414 bytes) - added by coffee2code 13 years ago.
Square bracket syntax, rather than curly

Download all attachments as: .zip

Change History (6)

13 years ago

#1 @duck_
13 years ago

Like the patch, but our coding standards (or at least standard usage) are for array style access to characters i.e. $str[0]. See #13900.

#2 @coffee2code
13 years ago

Ah, missed that convention. Thanks! Revised patch, 17754.2.diff, attached.

13 years ago

Square bracket syntax, rather than curly

#3 @duck_
13 years ago

  • Milestone changed from Awaiting Review to 3.3

#4 @duck_
13 years ago

  • Owner set to duck_
  • Resolution set to fixed
  • Status changed from new to closed

In [18551]:

Replace regex in path_is_absolute() with simpler equality checks. props coffee2code. fixes #17754

Note: See TracTickets for help on using tickets.