-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: vi73552 Date: 03/23/99
The Java source code for java.lang.reflect.Method contains this
method:
/*
* Avoid clone()
*/
static Class[] copy(Class[] in) {
int l = in.length;
if (l == 0)
return in;
Class[] out = new Class[l];
for (int i = 0; i < l; i++)
out[i] = in[i];
return out;
}
This method appears to be rather inefficient in the way that it
copies elements from one array to the other. A better implementation
would be to use System.arraycopy.
static Class[] copy(Class[] in) {
int l = in.length;
if (l == 0)
return in;
Class[] out = new Class[l];
System.arraycopy(in, 0, out, 0, l);
return out;
}
I don't see why you'd want to avoid the use of clone(). The above
method would likely be slightly faster if it were written:
static Class[] copy(Class[] in) {
int l = in.length;
if (l == 0)
return in;
return (Class[])in.clone();
}
(Review ID: 55955)
======================================================================