Repository: netty/netty
File: common/src/main/java/io/netty/util/AsciiString.java (Java)

Code before:
                for (int i = 0; i < length; ++i) {
                    if (!equalsIgnoreCase(value[i], rhsValue[i])) {
                        return false;
                    }
                }
                return true;
            }
            return misalignedEqualsIgnoreCase(rhs, value, rhsValue);
        }

        for (int i = arrayOffset(), j = 0, end = length(); j < end; ++i, ++j) {
            if (!equalsIgnoreCase(b2c(value[i]), string.charAt(j))) {
                return false;
            }
        }
        return true;
    }

    private boolean misalignedEqualsIgnoreCase(AsciiString rhs, byte[] value, byte[] rhsValue) {
        for (int i = arrayOffset(), j = rhs.arrayOffset(), end = i + length(); i < end; ++i, ++j) {
            if (!equalsIgnoreCase(value[i], rhsValue[j])) {
                return false;
            }
        }
        return true;
    }

    /**
     * Copies the characters in this string to a character array.
     *
     * @return a character array containing the characters of this string.
     */
    public char[] toCharArray() {
        return toCharArray(0, length());
    }

    /**
     * Copies the characters in this string to a character array.
     *
     * @return a character array containing the characters of this string.
     */
    public char[] toCharArray(int start, int end) {
        int length = end - start;
        if (length == 0) {
            return EmptyArrays.EMPTY_CHARS;
        }

        if (isOutOfBounds(start, length, length())) {
            throw new IndexOutOfBoundsException("expected: " + "0 <= start(" + start + ") <= srcIdx + length("
                            + length + ") <= srcLen(" + length() + ')');
        }

Review comment (suggestion):
Not terribly important but passing in the `rhs` and the `rhsValue` is a strange signature: maybe we can either pass in the offset or get the array from `rhs`?.

Code after:
                for (int i = 0; i < value.length; ++i) {
                    if (!equalsIgnoreCase(value[i], otherValue[i])) {
                        return false;
                    }
                }
                return true;
            }
            return misalignedEqualsIgnoreCase(other);
        }

        byte[] value = this.value;
        for (int i = offset, j = 0; j < string.length(); ++i, ++j) {
            if (!equalsIgnoreCase(b2c(value[i]), string.charAt(j))) {
                return false;
            }
        }
        return true;
    }

    private boolean misalignedEqualsIgnoreCase(AsciiString other) {
        byte[] value = this.value;
        byte[] otherValue = other.value;
        for (int i = offset, j = other.offset, end = offset + length; i < end; ++i, ++j) {
            if (!equalsIgnoreCase(value[i], otherValue[j])) {
                return false;
            }
        }
        return true;
    }

    /**
     * Copies the characters in this string to a character array.
     *
     * @return a character array containing the characters of this string.
     */
    public char[] toCharArray() {
        return toCharArray(0, length());
    }

    /**
     * Copies the characters in this string to a character array.
     *
     * @return a character array containing the characters of this string.
     */
    public char[] toCharArray(int start, int end) {
        int length = end - start;
        if (length == 0) {
            return EmptyArrays.EMPTY_CHARS;
        }

        if (isOutOfBounds(start, length, length())) {