Opened 5 years ago
Closed 5 years ago
#48083 closed enhancement (fixed)
Use `**` operator to replace`pow()` function calls
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | trivial | Version: | 5.3 |
Component: | General | Keywords: | has-patch commit |
Focuses: | performance, coding-standards | Cc: |
Description
Another ticket for a PHP 5.6+ enhancement. With PHP 5.6, we can use the **
operator instead of pow()
function. Doc page of pow()
function also suggests to use the operator.
Using the **
operator is about 4 times faster too.
**
operator: https://www.php.net/manual/en/language.operators.arithmetic.phppow()
function: https://www.php.net/manual/en/function.pow.php- Simple benchmark: https://3v4l.org/LMRcp
Attached patch below will fix the only 2 instances we have in WordPress code base.
SimplePie and GetID3 libraries have this pattern more frequently. I see @jrf has created an issue in SimplePie about a new release, so I will open a PR there to see if we can get this in SimplePie upstream. GetID3 library requires PHP 5.3, so I don't think we can get this improvement to upstream.
Thank you.
Attachments (2)
Change History (7)
#1
@
5 years ago
Hi @ayeshrajans Yet another good idea ;-)
Reviewed & the changes themselves look ok, the patch just needs one space on the inside of the parentheses on both changed lines.
<?php if ( 8 < $size / ( 1024 ** 2 ) ) { $size = KB_IN_BYTES ** ( $log - $power )
Also saw you opened the PR to SimplePie 👍🏻.
Adding the link here for reference: https://github.com/simplepie/simplepie/pull/622
Improvements in the WP code base only, no third party libraries.