]> source.dussan.org Git - aspectj.git/commitdiff
Manual array copy
authorLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:35:54 +0000 (16:35 +0200)
committerLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:35:54 +0000 (16:35 +0200)
Reports the manual copying of array contents which may be replaced by calls to System.arraycopy().

Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
org.aspectj.ajdt.core/src/test/java/RunWeaveTests.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/Advice.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/PointcutRewriter.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java
testing/src/test/java/org/aspectj/testing/util/options/Values.java

index 6dfd5633f0fb00057f357c0f889714928adb72cb..af95fb3fc136f2d8eae6bd82c3945aba0bb13d2d 100644 (file)
@@ -178,9 +178,7 @@ public abstract class AjdocTestCase extends TestCase {
                args[3] = AjdocTests.ASPECTJRT_PATH.getPath();
                args[4] = "-d";
                args[5] = getAbsolutePathOutdir();
-               for (int i = 0; i < ajOptions.length; i++) {
-                       args[6 + i] = ajOptions[i];
-               }
+               System.arraycopy(ajOptions, 0, args, 6, ajOptions.length);
                for (int i = 0; i < inputFiles.length; i++) {
                        args[6 + i + ajOptions.length] = inputFiles[i].getAbsolutePath();
                }
@@ -252,9 +250,7 @@ public abstract class AjdocTestCase extends TestCase {
                args[4] = getAbsolutePathOutdir();
                args[5] = "-sourcepath";
                args[6] = getAbsoluteProjectDir();
-               for (int i = 0; i < directoryNames.length; i++) {
-                       args[7 + i] = directoryNames[i];
-               }
+               System.arraycopy(directoryNames, 0, args, 7, directoryNames.length);
                org.aspectj.tools.ajdoc.Main.main(args);
        }
 
@@ -272,9 +268,7 @@ public abstract class AjdocTestCase extends TestCase {
                args[3] = getAbsolutePathOutdir();
                args[4] = "-sourcepath";
                args[5] = getAbsoluteProjectDir();
-               for (int i = 0; i < directoryNames.length; i++) {
-                       args[6 + i] = directoryNames[i];
-               }
+               System.arraycopy(directoryNames, 0, args, 6, directoryNames.length);
                org.aspectj.tools.ajdoc.Main.main(args);
        }
 
index e54ab44e29dfc9ad53c1e1e7c5db5d699c1cdc74..ad68e64d5bb04a06b46fd14fa380267441b8b246 100644 (file)
@@ -51,44 +51,30 @@ public class RunWeaveTests {
                        WeaveTest.main(
                                split(SMALL_PROGRAM_ARGS + "-echo -i " + ITERATIONS));
 
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[0][i] = WeaveTest.compileTimes[i];
+                       System.arraycopy(WeaveTest.compileTimes, 0, times[0], 0, ITERATIONS);
 
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[1][i] = WeaveTest.executionFastTimes[i];
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[2][i] = WeaveTest.executionMedTimes[i];
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[3][i] = WeaveTest.executionSlowTimes[i];
+                       System.arraycopy(WeaveTest.executionFastTimes, 0, times[1], 0, ITERATIONS);
+                       System.arraycopy(WeaveTest.executionMedTimes, 0, times[2], 0, ITERATIONS);
+                       System.arraycopy(WeaveTest.executionSlowTimes, 0, times[3], 0, ITERATIONS);
 
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[4][i] = WeaveTest.getFastTimes[i];
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[5][i] = WeaveTest.getMedTimes[i];
-                       for (int i = 0; i < ITERATIONS; i++)
-                               times[6][i] = WeaveTest.getSlowTimes[i]; 
+                       System.arraycopy(WeaveTest.getFastTimes, 0, times[4], 0, ITERATIONS);
+                       System.arraycopy(WeaveTest.getMedTimes, 0, times[5], 0, ITERATIONS);
+                       System.arraycopy(WeaveTest.getSlowTimes, 0, times[6], 0, ITERATIONS);
                }               
                
                if (RUN_MED) {
                        WeaveTest.main(
                                split(MEDIUM_PROGRAM_ARGS + "-echo -i " + ITERATIONS));
 
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[0][i] = WeaveTest.compileTimes[i - ITERATIONS];
+                       System.arraycopy(WeaveTest.compileTimes, 0, times[0], ITERATIONS, 2 * ITERATIONS - 3);
 
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[1][i] = WeaveTest.executionFastTimes[i - ITERATIONS];
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[2][i] = WeaveTest.executionMedTimes[i - ITERATIONS];
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[3][i] = WeaveTest.executionSlowTimes[i - ITERATIONS];
+                       System.arraycopy(WeaveTest.executionFastTimes, 0, times[1], ITERATIONS, 2 * ITERATIONS - 3);
+                       System.arraycopy(WeaveTest.executionMedTimes, 0, times[2], ITERATIONS, 2 * ITERATIONS - 3);
+                       System.arraycopy(WeaveTest.executionSlowTimes, 0, times[3], ITERATIONS, 2 * ITERATIONS - 3);
 
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[4][i] = WeaveTest.getFastTimes[i - ITERATIONS];
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[5][i] = WeaveTest.getMedTimes[i - ITERATIONS];
-                       for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
-                               times[6][i] = WeaveTest.getSlowTimes[i - ITERATIONS];
+                       System.arraycopy(WeaveTest.getFastTimes, 0, times[4], ITERATIONS, 2 * ITERATIONS - 3);
+                       System.arraycopy(WeaveTest.getMedTimes, 0, times[5], ITERATIONS, 2 * ITERATIONS - 3);
+                       System.arraycopy(WeaveTest.getSlowTimes, 0, times[6], ITERATIONS, 2 * ITERATIONS - 3);
                        
                }               
                
@@ -96,25 +82,15 @@ public class RunWeaveTests {
                        WeaveTest.main(
                                split(LARGE_PROGRAM_ARGS + "-echo -i " + ITERATIONS));
 
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[0][i] = WeaveTest.compileTimes[i - (2 * ITERATIONS)];
+                       System.arraycopy(WeaveTest.compileTimes, 0, times[0], 2 * ITERATIONS, 3 * ITERATIONS - 6);
 
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[1][i] =
-                                       WeaveTest.executionFastTimes[i - (2 * ITERATIONS)];
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[2][i] =
-                                       WeaveTest.executionMedTimes[i - (2 * ITERATIONS)];
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[3][i] =
-                                       WeaveTest.executionSlowTimes[i - (2 * ITERATIONS)];
+                       System.arraycopy(WeaveTest.executionFastTimes, 0, times[1], 2 * ITERATIONS, 3 * ITERATIONS - 6);
+                       System.arraycopy(WeaveTest.executionMedTimes, 0, times[2], 2 * ITERATIONS, 3 * ITERATIONS - 6);
+                       System.arraycopy(WeaveTest.executionSlowTimes, 0, times[3], 2 * ITERATIONS, 3 * ITERATIONS - 6);
 
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[4][i] = WeaveTest.getFastTimes[i - (2 * ITERATIONS)];
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[5][i] = WeaveTest.getMedTimes[i - (2 * ITERATIONS)];
-                       for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
-                               times[6][i] = WeaveTest.getSlowTimes[i - (2 * ITERATIONS)];
+                       System.arraycopy(WeaveTest.getFastTimes, 0, times[4], 2 * ITERATIONS, 3 * ITERATIONS - 6);
+                       System.arraycopy(WeaveTest.getMedTimes, 0, times[5], 2 * ITERATIONS, 3 * ITERATIONS - 6);
+                       System.arraycopy(WeaveTest.getSlowTimes, 0, times[6], 2 * ITERATIONS, 3 * ITERATIONS - 6);
                        
                }               
 
index cd786e7246edffcff277ce948698013ec2ad2a3b..d759bc721922df8d40c44b882de578b97da43738 100644 (file)
@@ -304,9 +304,7 @@ public abstract class Advice extends ShadowMunger {
                        return allNames;
                }
                String[] result = new String[getBaseParameterCount()];
-               for (int i = 0; i < result.length; i++) {
-                       result[i] = allNames[i];
-               }
+               if (result.length >= 0) System.arraycopy(allNames, 0, result, 0, result.length);
                return result;
        }
 
index 4e1ef74dfa3d5b072f84c6a14e3cf9dd583804c8..c0fed9aee04d4a861d526f7712547804d1d87e47 100644 (file)
@@ -252,9 +252,7 @@ public class PointcutRewriter {
                }
                // otherwise ...
                Pointcut[] subset = new Pointcut[ps.length - 1];
-               for (int i = 1; i < ps.length; i++) {
-                       subset[i - 1] = ps[i];
-               }
+               if (ps.length - 1 >= 0) System.arraycopy(ps, 1, subset, 0, ps.length - 1);
                return new AndPointcut(ps[0], createAndsFor(subset));
        }
 
index b8e58c3425d36dd73d214326c15d7dbefa6f91e0..c5f44ae0fe20bf2b967c4286ec4e582d6d4e9914 100644 (file)
@@ -588,9 +588,7 @@ public class WildTypePattern extends TypePattern {
        @Override
        public TypePattern parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
                NamePattern[] newNamePatterns = new NamePattern[namePatterns.length];
-               for (int i = 0; i < namePatterns.length; i++) {
-                       newNamePatterns[i] = namePatterns[i];
-               }
+               System.arraycopy(namePatterns, 0, newNamePatterns, 0, namePatterns.length);
                if (newNamePatterns.length == 1) {
                        String simpleName = newNamePatterns[0].maybeGetSimpleName();
                        if (simpleName != null) {
index 608d4a610a04e6751e25bdb94b4978ba4aed7e57..af81692b7da07bed38ce07e46ad2389a0abb3305 100644 (file)
@@ -698,9 +698,7 @@ public class Values {
         private void add(int i) {
             if (insert >= input.length) {
                 int[] temp = new int[insert + 256];
-                for (int j = 0; j < input.length; j++) {
-                    temp[j] = input[j];
-                }
+                               System.arraycopy(input, 0, temp, 0, input.length);
                 input = temp;
             }
             input[insert++] = i;
@@ -708,9 +706,7 @@ public class Values {
 
         private int[] getList() {
             int[] result = new int[insert];
-            for (int i = 0; i < result.length; i++) {
-                result[i] = input[i];
-            }
+                       if (result.length >= 0) System.arraycopy(input, 0, result, 0, result.length);
             return result;
         }
     }