You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2022/06/27 20:37:10 UTC
[commons-numbers] branch master updated: * Use Math.min * Use System.arraycopy
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
The following commit(s) were added to refs/heads/master by this push:
new 1a8a73fc * Use Math.min * Use System.arraycopy
1a8a73fc is described below
commit 1a8a73fc9dadee2e44313e80ef63cf6c6ff848a4
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sun Jun 26 22:41:13 2022 +0200
* Use Math.min
* Use System.arraycopy
Revert some changes.
---
.../org/apache/commons/numbers/combinatorics/LogFactorial.java | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/LogFactorial.java b/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/LogFactorial.java
index 76af8a2b..6182fe75 100644
--- a/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/LogFactorial.java
+++ b/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/LogFactorial.java
@@ -55,15 +55,14 @@ public final class LogFactorial {
int endCopy;
if (cache == null || cache.length <= beginCopy) {
endCopy = beginCopy;
- } else if (cache.length <= numValues) {
- endCopy = cache.length;
} else {
- endCopy = numValues;
+ endCopy = Math.min(cache.length, numValues);
}
+
// Copy available values.
- for (int i = beginCopy; i < endCopy; i++) {
- logFactorials[i] = cache[i];
+ if (endCopy - beginCopy > 0) {
+ System.arraycopy(cache, beginCopy, logFactorials, beginCopy, endCopy - beginCopy);
}
// Precompute.