Skip to content

Commit

Permalink
[GR-32791] Avoid Arrays.copyOf in SchedulePhaseBenchmark.
Browse files Browse the repository at this point in the history
PullRequest: graal/9485
  • Loading branch information
zapster committed Aug 7, 2021
2 parents 058e893 + cd3aa6e commit 7e6c2bb
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
*/
package org.graalvm.compiler.microbenchmarks.graal;

import java.util.Arrays;

import org.graalvm.compiler.phases.schedule.SchedulePhase;
import org.openjdk.jmh.annotations.Benchmark;

import org.graalvm.compiler.microbenchmarks.graal.util.MethodSpec;
import org.graalvm.compiler.microbenchmarks.graal.util.ScheduleState;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.phases.schedule.SchedulePhase;
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
import org.openjdk.jmh.annotations.Benchmark;

public class SchedulePhaseBenchmark extends GraalBenchmark {

Expand Down Expand Up @@ -77,11 +74,17 @@ public static int[] intersectionSnippet(int[] in1, int[] in2) {
}
}
if (next < result.length) {
result = Arrays.copyOf(result, next);
result = copyOf(result, next);
}
return result;
}

private static int[] copyOf(int[] original, int newLength) {
int[] copy = new int[newLength];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
return copy;
}

// Checkstyle: stop method name check
@MethodSpec(declaringClass = SchedulePhaseBenchmark.class, name = "intersectionSnippet")
public static class IntersectionState_LATEST_OPTIMAL extends ScheduleState {
Expand Down

0 comments on commit 7e6c2bb

Please sign in to comment.