[issue13155] Optimize finding the max character width

Antoine Pitrou report at bugs.python.org
Wed Oct 12 02:24:32 CEST 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

> > Ok, updated patch.
> 
> "ret = ~mask + 1;" looks wrong: (~0xFFFFFF80+1) gives 128, not 127.

That's on purpose, since the mask has just matched. If 0xFFFFFF80
matches, then the max char can't be 127, it has to be at least 128.

>  I don't see why you need:
> 
> +    if (ret < 128)
> +        return 127;
> +    if (ret < 256)
> +        return 255;

Because otherwise you're returning 0xFFFF in the following line:

    if (ret < 0x10000)
        return 0xFFFF;

> #undef ASCII_CHAR_MASK should be #undef UCS1_ASCII_CHAR_MASK

Ha, funny that gcc doesn't say anything.
I also forgot to #under MASK_*.

> #error Invalid STRINGLIB_SIZEOF_CHAR (must be 1, 2 or 4)
> should be
> #error Invalid STRINGLIB_SIZEOF_CHAR (must be 2 or 4)

Well, no. 1 is a legal value, even though it's handled elsewhere, so the
error message is right.

> Why do you need these forward declarations? It's maybe related to another patch?

It's because I'm moving the stringlib #includes up in unicodeobject.c,
and stringlib calls these functions.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13155>
_______________________________________


More information about the Python-bugs-list mailing list