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

Code before:
    }

    /**
     * Compares the specified string to this string ignoring the case of the characters and returns true if they are
     * equal.
     *
     * @param string the string to compare.
     * @return {@code true} if the specified string is equal to this string, {@code false} otherwise.
     */
    public boolean contentEqualsIgnoreCase(CharSequence string) {
        if (this == string) {
            return true;
        }

        if (string == null || string.length() != length()) {
            return false;
        }

        byte[] value = this.value;
        if (string instanceof AsciiString) {
            AsciiString rhs = (AsciiString) string;
            byte[] rhsValue = rhs.value;
            if ((arrayOffset() | rhs.arrayOffset()) == 0) {
                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;
    }

    /**

Review comment (refactor):
Will it benefit JIT more if we extract this path into its own method (like `alignedEqualsIgnoreCase`) and make both methods static?

Code after:
    }

    /**
     * Compares the specified string to this string ignoring the case of the characters and returns true if they are
     * equal.
     *
     * @param string the string to compare.
     * @return {@code true} if the specified string is equal to this string, {@code false} otherwise.
     */
    public boolean contentEqualsIgnoreCase(CharSequence string) {
        if (this == string) {
            return true;
        }

        if (string == null || string.length() != length()) {
            return false;
        }

        if (string instanceof AsciiString) {
            AsciiString other = (AsciiString) string;
            byte[] value = this.value;
            if (offset == 0 && other.offset == 0 && length == value.length) {
                byte[] otherValue = other.value;
                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;