Message236931
Yes, this is a technique commonly used in STL implementations. This is why sizes and indices in STL are unsigned.
But in CPython implementation sizes are signed (Py_ssize_t). The problem with using this optimization (rather low-level than high-level) is that we need to know unsigned version of the type of compared values.
> - if (i < 0 || i >= Py_SIZE(a)) {
> + if ((unsigned)i >= (unsigned)(Py_SIZE(a))) {
Here is a bug. The type of i and Py_SIZE(a) is Py_ssize_t, so when casted to unsigned int, highest bits are lost. The correct casting type is size_t.
In changeset 5942fd9ab335 you introduced a bug. |
|
Date |
User |
Action |
Args |
2015-03-01 05:39:46 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger |
2015-03-01 05:39:46 | serhiy.storchaka | set | messageid: <1425188386.54.0.539730831229.issue23553@psf.upfronthosting.co.za> |
2015-03-01 05:39:46 | serhiy.storchaka | link | issue23553 messages |
2015-03-01 05:39:45 | serhiy.storchaka | create | |
|