HaraldKi opened a new pull request, #138: URL: https://github.com/apache/commons-numbers/pull/138
All classes already implementing Addition and Multiplication got their specialized versions instead of just calling equals() on zero() or one() respectively to avoid potentially expensive operations, like BigFraction creating fresh copies of numerator and/or denominator if either is negative. ## Disclaimer - I read the 'Contributing' page on commons.apache.org, but it mentions gitbox.apache.org, so I consider it a bit out of date and - I prefer the simple statement in the README.md: we accept pull requests via GitHub :-) ## Rationale While coding polynomial computations over differing fields with commons math3 where the field is a generic parameter in the implementation of monomials and polynomials, I coded the comparison with `zero` and `one` as `coefficient.getField().getZero().equals(coefficient)`. Looking a bit after performance with async-profiler I saw that the `equals()` required a non-negligible amount of CPU power, in particular for the BigFraction field. I implemented this pull request, tried it in my code and the check on zero is not visible in the profiler output anymore. ## Alternatives Instead of adding two new methods to interfaces it may be possible to improve the `equals()` methods of the classes implementing `zero()` and `one()` to specifically watch out for comparison with these constants and invoke faster specialized code. Yet this seems like introducing somewhat nontrivial, even messy code. Whether this is preferable over an incompatible interface extension is hard to judge for an outsider. ## Note This pull request does not increment the version number, which seems to be needed before a merge as I had to compile with ``` mvn install -Dcommons.japicmp.breakBuildOnBinaryIncompatibleModifications=false ``` I rather leave the versioning to the experts. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
