From: Lars Grefer Date: Sat, 15 Aug 2020 14:35:54 +0000 (+0200) Subject: Manual array copy X-Git-Tag: V1_9_7M1~9^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d66bec041a857bc3076a20dfeb1aa6037b020db1;p=aspectj.git Manual array copy Reports the manual copying of array contents which may be replaced by calls to System.arraycopy(). Signed-off-by: Lars Grefer --- diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java index 6dfd5633f..af95fb3fc 100644 --- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java +++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java @@ -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); } diff --git a/org.aspectj.ajdt.core/src/test/java/RunWeaveTests.java b/org.aspectj.ajdt.core/src/test/java/RunWeaveTests.java index e54ab44e2..ad68e64d5 100644 --- a/org.aspectj.ajdt.core/src/test/java/RunWeaveTests.java +++ b/org.aspectj.ajdt.core/src/test/java/RunWeaveTests.java @@ -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); } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Advice.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Advice.java index cd786e724..d759bc721 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Advice.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Advice.java @@ -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; } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/PointcutRewriter.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/PointcutRewriter.java index 4e1ef74df..c0fed9aee 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/PointcutRewriter.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/PointcutRewriter.java @@ -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)); } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java index b8e58c342..c5f44ae0f 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java @@ -588,9 +588,7 @@ public class WildTypePattern extends TypePattern { @Override public TypePattern parameterizeWith(Map 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) { diff --git a/testing/src/test/java/org/aspectj/testing/util/options/Values.java b/testing/src/test/java/org/aspectj/testing/util/options/Values.java index 608d4a610..af81692b7 100644 --- a/testing/src/test/java/org/aspectj/testing/util/options/Values.java +++ b/testing/src/test/java/org/aspectj/testing/util/options/Values.java @@ -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; } }