Current layout
Currently the _dictkeysobject struct is laid out like this:
ptr ----> +--------------+
| header |
+--------------+
| indices |
+--------------+
| keys |
+--------------+
which requires some relatively expensive calculation to find the start of the keys, as the indices are not only variable in number, but variable in size also.
Proposed layout
If instead it is laid out as follows:
+--------------+
| indices |
ptr ----> +--------------+
| header |
+--------------+
| keys |
+--------------+
and the indices laid from highest to lowest with 0 just before ptr, finding the start of the keys is as simple as ptr->keys . Accessing an index is no slower, and the code barely any more complex.
Linked PRs
Current layout
Currently the
_dictkeysobjectstruct is laid out like this:which requires some relatively expensive calculation to find the start of the keys, as the indices are not only variable in number, but variable in size also.
Proposed layout
If instead it is laid out as follows:
and the indices laid from highest to lowest with 0 just before
ptr, finding the start of the keys is as simple asptr->keys. Accessing an index is no slower, and the code barely any more complex.Linked PRs