smali

суббота, 24 сентября 2016 г.

What is more efficient: System.arraycopy vs Arrays.copyOf?


http://stackoverflow.com/questions/2589741/what-is-more-efficient-system-arraycopy-vs-arrays-copyof

The difference is that Arrays.copyOf does not only copy elements, it also creates a new array. System.arrayCopy copies into an existing array.
Here is the source for Arrays.copyOf, as you can see it uses System.arraycopy internally to fill up the new array.
  public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {
    T[] copy = ((Object)newType == (Object)Object[].class)
        ? (T[]) new Object[newLength]
        : (T[]) Array.newInstance(newType.getComponentType(), newLength);
    System.arraycopy(original, 0, copy, 0,
                     Math.min(original.length, newLength));
    return copy;
}

http://hg.openjdk.java.net/jdk8/jdk8/jdk/


Комментариев нет:

Отправить комментарий