You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/10/20 21:49:00 UTC

[GitHub] [commons-math] aherbert commented on a diff in pull request #219: MATH-1569 - Manual array copy.

aherbert commented on code in PR #219:
URL: https://github.com/apache/commons-math/pull/219#discussion_r1001149401


##########
commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/function/Logit.java:
##########
@@ -182,9 +182,7 @@ public DerivativeStructure value(final DerivativeStructure t)
             //  for x close to hi the signs will always be +inf)
             // this is probably overkill, since the call to compose at the end
             // of the method will transform most infinities into NaN ...
-            for (int i = 2; i < f.length; ++i) {
-                f[i] = f[i - 2];
-            }
+            if (f.length - 2 >= 0) System.arraycopy(f, 0, f, 2, f.length - 2);

Review Comment:
   `> 0`



##########
commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java:
##########
@@ -752,9 +752,7 @@ private void updateBD(double negccov) {
      * @param val Current best fitness value.
      */
     private static void push(double[] vals, double val) {
-        for (int i = vals.length-1; i > 0; i--) {
-            vals[i] = vals[i-1];
-        }
+        if (vals.length - 1 >= 0) System.arraycopy(vals, 0, vals, 1, vals.length - 1);

Review Comment:
   `> 0`



##########
commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java:
##########
@@ -663,9 +663,7 @@ public Dfp getTwo() {
     /** Shift the mantissa left, and adjust the exponent to compensate.
      */
     protected void shiftLeft() {
-        for (int i = mant.length - 1; i > 0; i--) {
-            mant[i] = mant[i - 1];
-        }
+        if (mant.length - 1 >= 0) System.arraycopy(mant, 0, mant, 1, mant.length - 1);

Review Comment:
   use `> 0` as arraycopy with a length of 0 is a wasted call to a native method. Add enclosing braces to fix checkstyle.



##########
commons-math-legacy-core/src/main/java/org/apache/commons/math4/legacy/core/dfp/Dfp.java:
##########
@@ -675,9 +673,7 @@ uses shiftRight() */
     /** Shift the mantissa right, and adjust the exponent to compensate.
      */
     protected void shiftRight() {
-        for (int i = 0; i < mant.length - 1; i++) {
-            mant[i] = mant[i + 1];
-        }
+        if (mant.length - 1 >= 0) System.arraycopy(mant, 1, mant, 0, mant.length - 1);

Review Comment:
   `> 0`



##########
commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/ode/nonstiff/AdamsNordsieckFieldTransformer.java:
##########
@@ -170,10 +170,8 @@ private AdamsNordsieckFieldTransformer(final Field<T> field, final int n) {
         // Nordsieck to multistep, then shifting rows to represent step advance
         // then applying inverse transform
         T[][] shiftedP = bigP.getData();
-        for (int i = shiftedP.length - 1; i > 0; --i) {
-            // shift rows
-            shiftedP[i] = shiftedP[i - 1];
-        }
+        // shift rows
+        if (shiftedP.length - 1 >= 0) System.arraycopy(shiftedP, 0, shiftedP, 1, shiftedP.length - 1);

Review Comment:
   `> 0`



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org