Am I mad ???

2nd. correction:

But
        for (int i = offset; i < offset + count; i++) {
            int c = codePoints[i];
            char plane = (char)(c >>> 16);
            if (plane == 0)
                n += 1;
            else if (plane < 0x11)
                n += 2;
            else throw new IllegalArgumentException(Integer.toString(c));
        }
has too only 2 branches and additionally could benefit from tiny 16-bit comparisons. The shift additionally could be omitted on CPU's which can benefit from 6933327.

Instead:
        for (int i = offset; i < offset + count; i++) {
            int c = codePoints[i];
            if (c >= Character.MIN_VALUE &&
                c <=  Character.MAX_VALUE)
                n += 1;
            else if (c >= Character.MIN_SUPPLEMENTARY_CODE_POINT &&
                c <=  Character.MAX_SUPPLEMENTARY_CODE_POINT)
                n += 2;
            else throw new IllegalArgumentException(Integer.toString(c));
        }
needs 4 branches and 4 32-bit comparisons.

-Ulf



Reply via email to