-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraal-10565.java
More file actions
40 lines (36 loc) · 1.28 KB
/
Graal-10565.java
File metadata and controls
40 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.lang.reflect.Array;
public class Test {
public static int indexOf(final float[] array, final float target) {
for (int i = 0; i < array.length; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
public static float[] remove(final float[] array, final int index) {
final int length = Array.getLength(array);
final Object result = Array.newInstance(array.getClass().getComponentType(), length - 1);
// throws exception when index is -1
System.arraycopy(array, 0, result, 0, index);
System.arraycopy(array, index + 1, result, index, length - index - 1);
return (float[])result;
}
public static float[] removeElement(final float[] array, final float target) {
int index = indexOf(array, target);
return remove(array, index);
}
public static void main(String[] args) {
int N = 1000000;
Object[] results = new Object[N];
float[] arr = new float[] { 1 };
for (int i = 0; i < N; ++i) {
try {
float target = (float) i % 13;
results[i] = removeElement(arr, target);
} catch (Throwable e) {
results[i] = null;
}
}
}
}