-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigNumber::of performance update #77
Conversation
SebastienDug
commented
Nov 10, 2023
- Split regex for Rational and Numerical
- Exception method is static to the class instead of being created dynamically for each call to BigNumber::of
- Added flag to pregMatch to return no matches as NULL instead of manipulating empty string and converting it to null
- leanCleanup introduced as there was a concatenation of sign to pass to the cleanup function which then removes the sign from the string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR, this brings an appreciable performance improvement!
Let's improve a few things and merge it!
src/BigNumber.php
Outdated
|
||
$unscaledValue = self::cleanUp(($sign ?? ''). $integral . $fractional); | ||
$unscaledValue = self::leanCleanUp(($sign ?? ''), $integral . $fractional); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$unscaledValue = self::leanCleanUp(($sign ?? ''), $integral . $fractional); | |
$unscaledValue = self::cleanUp($sign, $integral . $fractional); |
After leanCleanUp
has been renamed to cleanUp
.
src/BigNumber.php
Outdated
'(?<integral>[0-9]+)?' . | ||
'(?<point>\.)?' . | ||
'(?<fractional>[0-9]+)?' . | ||
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'(?<integral>[0-9]+)?' . | |
'(?<point>\.)?' . | |
'(?<fractional>[0-9]+)?' . | |
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' . | |
'(?<integral>[0-9]+)?' . | |
'(?<point>\.)?' . | |
'(?<fractional>[0-9]+)?' . | |
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' . |
src/BigNumber.php
Outdated
'/^' . | ||
'(?<sign>[\-\+])?' . | ||
'(?<numerator>[0-9]+)' . | ||
'\/?' . | ||
'(?<denominator>[0-9]+)' . | ||
'$/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'/^' . | |
'(?<sign>[\-\+])?' . | |
'(?<numerator>[0-9]+)' . | |
'\/?' . | |
'(?<denominator>[0-9]+)' . | |
'$/'; | |
'/^' . | |
'(?<sign>[\-\+])?' . | |
'(?<numerator>[0-9]+)' . | |
'\/?' . | |
'(?<denominator>[0-9]+)' . | |
'$/'; |
src/BigNumber.php
Outdated
/** | ||
* Throws a NumberFormatException for the given value. | ||
* @psalm-pure | ||
*/ | ||
protected static function throwException(string $value) : void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces + private
:
/** | |
* Throws a NumberFormatException for the given value. | |
* @psalm-pure | |
*/ | |
protected static function throwException(string $value) : void { | |
/** | |
* Throws a NumberFormatException for the given value. | |
* | |
* @psalm-pure | |
*/ | |
private static function throwException(string $value) : void { |
src/BigNumber.php
Outdated
} | ||
|
||
return new BigDecimal($unscaledValue, $scale); | ||
} | ||
$integral = self::leanCleanUp(($sign ?? ''), $integral); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$integral = self::leanCleanUp(($sign ?? ''), $integral); | |
$integral = self::cleanUp($sign, $integral); |
After leanCleanUp
has been renamed to cleanUp
.
Hello again,
Sorry for the delay,
The changes requested have been applied and the branch has been synched.
Thanks,
Sebastien Duguay
|
Thank you, @SebastienDug! |
Released as 0.12.1. |
Good to hear.
I will reach out if we find other issues we could improve upon.
Thanks,
Sebastien Duguay
|