Skip to content

Conversation

@SebastienDug
Copy link
Contributor

  1. Split regex for Rational and Numerical
  2. Exception method is static to the class instead of being created dynamically for each call to BigNumber::of
  3. Added flag to pregMatch to return no matches as NULL instead of manipulating empty string and converting it to null
  4. leanCleanup introduced as there was a concatenation of sign to pass to the cleanup function which then removes the sign from the string

Copy link
Member

@BenMorel BenMorel left a 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!

}

$unscaledValue = self::cleanUp(($sign ?? ''). $integral . $fractional);
$unscaledValue = self::leanCleanUp(($sign ?? ''), $integral . $fractional);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$unscaledValue = self::leanCleanUp(($sign ?? ''), $integral . $fractional);
$unscaledValue = self::cleanUp($sign, $integral . $fractional);

After leanCleanUp has been renamed to cleanUp.

Comment on lines 25 to 28
'(?<integral>[0-9]+)?' .
'(?<point>\.)?' .
'(?<fractional>[0-9]+)?' .
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'(?<integral>[0-9]+)?' .
'(?<point>\.)?' .
'(?<fractional>[0-9]+)?' .
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' .
'(?<integral>[0-9]+)?' .
'(?<point>\.)?' .
'(?<fractional>[0-9]+)?' .
'(?:[eE](?<exponent>[\-\+]?[0-9]+))?' .

Comment on lines 35 to 40
'/^' .
'(?<sign>[\-\+])?' .
'(?<numerator>[0-9]+)' .
'\/?' .
'(?<denominator>[0-9]+)' .
'$/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'/^' .
'(?<sign>[\-\+])?' .
'(?<numerator>[0-9]+)' .
'\/?' .
'(?<denominator>[0-9]+)' .
'$/';
'/^' .
'(?<sign>[\-\+])?' .
'(?<numerator>[0-9]+)' .
'\/?' .
'(?<denominator>[0-9]+)' .
'$/';

Comment on lines 149 to 153
/**
* Throws a NumberFormatException for the given value.
* @psalm-pure
*/
protected static function throwException(string $value) : void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces + private:

Suggested change
/**
* 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 {


return new BigDecimal($unscaledValue, $scale);
}
$integral = self::leanCleanUp(($sign ?? ''), $integral);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$integral = self::leanCleanUp(($sign ?? ''), $integral);
$integral = self::cleanUp($sign, $integral);

After leanCleanUp has been renamed to cleanUp.

@SebastienDug
Copy link
Contributor Author

SebastienDug commented Nov 27, 2023 via email

@BenMorel BenMorel merged commit 57a1758 into brick:master Nov 29, 2023
@BenMorel
Copy link
Member

Thank you, @SebastienDug!

@BenMorel
Copy link
Member

Released as 0.12.1.

@SebastienDug
Copy link
Contributor Author

SebastienDug commented Nov 30, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants