import javaemul.internal.ArrayHelper; //导入方法依赖的package包/类
public static void arraycopy(Object src, int srcOfs, Object dest, int destOfs, int len) {
checkNotNull(src, "src");
checkNotNull(dest, "dest");
// TODO: right now, all checks are disabled but could be reactivated
// when appropriate support is available
// Class> srcType = src.getClass();
// Class> destType = dest.getClass();
// TODO: support isArray() as a macro
// checkArrayType(srcType.isArray(), "srcType is not an array");
// checkArrayType(destType.isArray(), "destType is not an array");
// TODO: support getComponentType() as a macro
// Class> srcComp = srcType.getComponentType();
// Class> destComp = destType.getComponentType();
// checkArrayType(arrayTypeMatch(srcComp, destComp), "Array types don't
// match");
int srclen = ArrayHelper.getLength(src);
int destlen = ArrayHelper.getLength(dest);
if (srcOfs < 0 || destOfs < 0 || len < 0 || srcOfs + len > srclen || destOfs + len > destlen) {
throw new IndexOutOfBoundsException();
}
/*
* If the arrays are not references or if they are exactly the same
* type, we can copy them in native code for speed. Otherwise, we have
* to copy them in Java so we get appropriate errors.
*/
// if ((!srcComp.isPrimitive() || srcComp.isArray()) &&
// !srcType.equals(destType)) {
// // copy in Java to make sure we get ArrayStoreExceptions if the
// // values
// // aren't compatible
// Object[] srcArray = (Object[]) src;
// Object[] destArray = (Object[]) dest;
// if (src == dest && srcOfs < destOfs) {
// // TODO(jat): how does backward copies handle failures in the
// // middle?
// // copy backwards to avoid destructive copies
// srcOfs += len;
// for (int destEnd = destOfs + len; destEnd-- > destOfs;) {
// destArray[destEnd] = srcArray[--srcOfs];
// }
// } else {
// for (int destEnd = destOfs + len; destOfs < destEnd;) {
// destArray[destOfs++] = srcArray[srcOfs++];
// }
// }
// } else
if (len > 0) {
ArrayHelper.copy(src, srcOfs, dest, destOfs, len);
}
}