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

Avoid unnecessary array fill after creation in com.sun.media.sound

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P5 P5
    • 21
    • None
    • client-libs

      There a few places in com.sun.media.sound where a new array is created and then immediately filled with default values.
      1. com.sun.media.sound.ModelInstrument#getChannels

                  boolean[] ch = new boolean[16];
                  for (int i = 0; i < ch.length; i++)
                      ch[i] = false;

      2. com.sun.media.sound.SoftChannel#dontResetControls

          private static final boolean[] dontResetControls = new boolean[128];
          static {
              for (int i = 0; i < dontResetControls.length; i++)
                  dontResetControls[i] = false;

      3. com.sun.media.sound.SoftChannel#controlChangePerNote

                  keybasedcontroller_active[noteNumber] = new boolean[128];
                  Arrays.fill(keybasedcontroller_active[noteNumber], false);
                  keybasedcontroller_value[noteNumber] = new double[128];
                  Arrays.fill(keybasedcontroller_value[noteNumber], 0);

      4. com.sun.media.sound.SoftPerformer#SoftPerformer

              midi_ctrl_connections = new int[128][];
              for (int i = 0; i < midi_ctrl_connections.length; i++) {
                  midi_ctrl_connections[i] = null;
              }
              midi_connections = new int[5][];
              for (int i = 0; i < midi_connections.length; i++) {
                  midi_connections[i] = null;
              }

      It's redundant. Java guarantees that all elements of array have default values after array creation.

            aturbanov Andrey Turbanov
            aturbanov Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: