Exemple #1
0
  /** {@inheritDoc} */
  @Override
  public void writeTo(AnnotatedOutput out) {
    int sz = values.size();

    out.writeShort(Opcodes.FILL_ARRAY_DATA_PAYLOAD);
    out.writeShort(elemWidth);
    out.writeInt(initLength);

    // For speed reasons, replicate the for loop in each case
    switch (elemWidth) {
      case 1:
        {
          for (int i = 0; i < sz; i++) {
            Constant cst = values.get(i);
            out.writeByte((byte) ((CstLiteral32) cst).getIntBits());
          }
          break;
        }
      case 2:
        {
          for (int i = 0; i < sz; i++) {
            Constant cst = values.get(i);
            out.writeShort((short) ((CstLiteral32) cst).getIntBits());
          }
          break;
        }
      case 4:
        {
          for (int i = 0; i < sz; i++) {
            Constant cst = values.get(i);
            out.writeInt(((CstLiteral32) cst).getIntBits());
          }
          break;
        }
      case 8:
        {
          for (int i = 0; i < sz; i++) {
            Constant cst = values.get(i);
            out.writeLong(((CstLiteral64) cst).getLongBits());
          }
          break;
        }
      default:
        break;
    }

    // Pad one byte to make the size of data table multiples of 16-bits
    if (elemWidth == 1 && (sz % 2 != 0)) {
      out.writeByte(0x00);
    }
  }