int newFromLength = pointer;
//adding free indices that do not present in {@code from} array to it
ArraysUtils.quickSort(from, 0, pointer, to);
IntArrayList list = new IntArrayList();
for (i = 0; i < freeIndices.length; ++i)
if (Arrays.binarySearch(from, 0, pointer, freeIndices[i]) < 0) {
if (newFromLength < oldFromLength)
from[newFromLength] = to[newFromLength] = freeIndices[i];
else
list.add(freeIndices[i]);
++newFromLength;
}
// if newFromLength < oldFromLength then list must be
// empty and {@code from} and {@code to} arrays
// will be simply truncated so subsequent
// {@code arraycopy(...)} will do nothing
// if newFromLength > oldFromLength then list is not empty
// and it will be appended to {@code from} and {@code to}
if (newFromLength < oldFromLength) {
from = Arrays.copyOfRange(from, 0, newFromLength);
to = Arrays.copyOfRange(to, 0, newFromLength);
} else if (newFromLength > oldFromLength) {
int[] toAdd = list.toArray();
from = Arrays.copyOfRange(from, 0, newFromLength);
to = Arrays.copyOfRange(to, 0, newFromLength);
System.arraycopy(toAdd, 0, from, oldFromLength, toAdd.length);
System.arraycopy(toAdd, 0, to, oldFromLength, toAdd.length);
}