Here you can find the source of fill(final Object[] array, final int start, final int end, final Object value)
Parameter | Description |
---|---|
array | The array to fill. Must not be null. |
start | The first index of the array to be set to value inclusive. |
end | The last index of the array to be set to value exclusive. |
value | The value to put in the array. |
public static void fill(final Object[] array, final int start, final int end, final Object value)
//package com.java2s; //License from project: Apache License import java.util.Arrays; public class Main { private static final int LINE_SIZE = 1024; /**//from w ww . ja v a 2s. com * Fill the specified segment of an array with the provided value. Initializes a small amount of values * directly, larger values are them copied using {@link System#arraycopy(Object, int, Object, int, int)} * on the previous section in order to make sure the accessed values are in the L1 cache. * * @param array The array to fill. Must not be null. * @param start The first index of the array to be set to value inclusive. * @param end The last index of the array to be set to value exclusive. * @param value The value to put in the array. */ public static void fill(final Object[] array, final int start, final int end, final Object value) { assert start >= 0 && start <= end; assert end <= array.length; assert array.length == 0 || array.length == pow2(array.length); final int n = LINE_SIZE; int i = Math.min(n, end); Arrays.fill(array, start, i, value); while (i < end) { System.arraycopy(array, i - n, array, i, n); i += n; } } public static int pow2(int c) { assert c > 0; c--; c |= c >> 1; c |= c >> 2; c |= c >> 4; c |= c >> 8; c |= c >> 16; c++; return c; } }