docs: @SuppressWarnings("PMD.AvoidArrayLoops")
    ArrayTagSet add(Tag tag) {
      if (length == 0) {
        return new ArrayTagSet(new String[] {tag.key(), tag.value()});
      } else {
        String[] newTags = new String[length + 2];
        String k = tag.key();
        int i = 0;
        for (; i < length && tags[i].compareTo(k) < 0; i += 2) {
          newTags[i] = tags[i];
          newTags[i + 1] = tags[i + 1];
        }
        if (i < length && tags[i].equals(k)) {
          // Override
          newTags[i++] = tag.key();
          newTags[i++] = tag.value();
          System.arraycopy(tags, i, newTags, i, length - i);
          i = length;
        } else {
          // Insert
          newTags[i] = tag.key();
          newTags[i + 1] = tag.value();
          System.arraycopy(tags, i, newTags, i + 2, length - i);
          i = newTags.length;
        }
        return new ArrayTagSet(newTags, i);
      }
    }