Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4222968

(reflect) java.lang.reflect.Method: An optimization

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs



      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)
      ======================================================================

            iris Iris Clark
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: