Skip to content
Permalink
Browse files
[Truffle] Use Array.getLength to avoid duplicating assertions.
  • Loading branch information
eregon committed Jan 13, 2015
1 parent 5f6aa00 commit 122c81bedfb762948085c2e5be9e94e94fae5a7f
Showing 1 changed file with 4 additions and 30 deletions.
@@ -14,6 +14,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;

import java.lang.reflect.Array;
import java.util.Arrays;

public abstract class ArrayUtils {
@@ -33,15 +34,6 @@ public static int[] extractRange(int[] source, int start, int end) {
return result;
}

private static boolean checkExtractRangeArgs(int[] source, int start, int end) {
assert source != null;
assert start >= 0;
assert start <= source.length;
assert end >= start;
assert end <= source.length;
return true;
}

/**
* Extracts part of an array into a newly allocated Object[] array. Does not perform safety checks on parameters.
* @param source the source array whose values should be extracted
@@ -57,15 +49,6 @@ public static long[] extractRange(long[] source, int start, int end) {
return result;
}

private static boolean checkExtractRangeArgs(long[] source, int start, int end) {
assert source != null;
assert start >= 0;
assert start <= source.length;
assert end >= start;
assert end <= source.length;
return true;
}

/**
* Extracts part of an array into a newly allocated Object[] array. Does not perform safety checks on parameters.
* @param source the source array whose values should be extracted
@@ -81,15 +64,6 @@ public static double[] extractRange(double[] source, int start, int end) {
return result;
}

private static boolean checkExtractRangeArgs(double[] source, int start, int end) {
assert source != null;
assert start >= 0;
assert start <= source.length;
assert end >= start;
assert end <= source.length;
return true;
}

/**
* Extracts part of an array into a newly allocated Object[] array. Does not perform safety checks on parameters.
* @param source the source array whose values should be extracted
@@ -105,12 +79,12 @@ public static Object[] extractRange(Object[] source, int start, int end) {
return result;
}

private static boolean checkExtractRangeArgs(Object[] source, int start, int end) {
private static boolean checkExtractRangeArgs(Object source, int start, int end) {
assert source != null;
assert start >= 0;
assert start <= source.length;
assert start <= Array.getLength(source);
assert end >= start;
assert end <= source.length;
assert end <= Array.getLength(source);
return true;
}

0 comments on commit 122c81b

Please sign in to comment.