WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 11 days ago

#42918 reviewing enhancement

Replace intval(), strval(), ... function calls with type casts

Reported by: ayeshrajans Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: performance Cc:

Description

PHP's intval(), strval(), floatval() and boolval() are from PHP 4 ages. PHP 5 and later has the type hinting pattern (e.g (int) $var) that is ~6x faster than their function-call counterpart.

There are over 250 such calls, and I'll upload a patch to replace them with type hints. The patch itself is large, but because intval() and (int) are identical in usage, I hope you can review it. The test suit passed (https://travis-ci.org/Ayesh/wordpress-develop/builds/317469175).

I have not changed anything in third party libraries (such as random_compat).

Thank you.

Attachments (4)

42918-php-typehints.patch (95.5 KB) - added by ayeshrajans 3 years ago.
ONe big patch with all changes
42918-2.patch (91.6 KB) - added by ayeshrajans 3 years ago.
Please disregard the previous patch. Uploading a new one with proper WP code styling. Thanks to https://github.com/Mahjouba91 for the review and additional fixes.
42918-php-typehints-2.patch (116.8 KB) - added by ayeshrajans 11 days ago.
Thanks a lot for picking this up. I rebased and added several more cases to the list. Tests: https://travis-ci.com/github/Ayesh/wordpress-develop/builds/184027317 (PHPCS linting fails at the moment), but unit tests pass in all versions.
42918-php-typehints-3.patch (116.6 KB) - added by ayeshrajans 11 days ago.
Similar to the last patch, but fixes all phpcs errors as well. Tests (all passing): https://travis-ci.com/github/Ayesh/wordpress-develop/builds/184028745

Download all attachments as: .zip

Change History (11)

@ayeshrajans
3 years ago

ONe big patch with all changes

#1 @desrosj
3 years ago

  • Focuses performance added
  • Keywords has-patch needs-testing added

@ayeshrajans
3 years ago

Please disregard the previous patch. Uploading a new one with proper WP code styling. Thanks to https://github.com/Mahjouba91 for the review and additional fixes.

#3 @pento
21 months ago

  • Version trunk deleted

#4 @sabernhardt
12 days ago

  • Keywords needs-refresh added; has-patch needs-testing removed

#5 @SergeyBiryukov
12 days ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#6 @johnbillion
11 days ago

  • Summary changed from Replace intval(), strval(), ... function calls with type hints to Replace intval(), strval(), ... function calls with type casts

@ayeshrajans
11 days ago

Thanks a lot for picking this up. I rebased and added several more cases to the list. Tests: https://travis-ci.com/github/Ayesh/wordpress-develop/builds/184027317 (PHPCS linting fails at the moment), but unit tests pass in all versions.

#7 @ayeshrajans
11 days ago

  • Keywords has-patch added; needs-refresh removed

@ayeshrajans
11 days ago

Similar to the last patch, but fixes all phpcs errors as well. Tests (all passing): https://travis-ci.com/github/Ayesh/wordpress-develop/builds/184028745

Note: See TracTickets for help on using tickets.