private static int encodedLengthGeneral(CharSequence sequence, int start) {
        int utf16Length = sequence.length();
        int utf8Length = 0;
        for (int i = start; i < utf16Length; i++) {
            char c = sequence.charAt(i);
            if (c < 0x800) {
                utf8Length += (0x7f - c) >>> 31; // branch free!
            } else {
                utf8Length += 2;
                // jdk7+: if (Character.isSurrogate(c)) {
                if (Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) {
                    // Check that we have a well-formed surrogate pair.
                    int cp = Character.codePointAt(sequence, i);
                    if (cp < MIN_SUPPLEMENTARY_CODE_POINT) {
                        throw new IllegalArgumentException("Unpaired surrogate at index " + i + " of " + utf16Length);
                    }
                    i++;
                }
            }
        }
        return utf8Length;
    }
Returns the number of bytes in the UTF-8-encoded form of {@code sequence}. For a string,
this method is equivalent to {@code string.getBytes(UTF_8).length}, but is more efficient in
both time and space.

@throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired
                                 surrogates)
jraft-core/src/main/java/com/alipay/sofa/jraft/util/internal/UnsafeUtf8Util.java