[Python-Dev] Dictionary tuning
Guido van Rossum
guido@python.org
Tue, 29 Apr 2003 06:19:18 -0400
> What could be much worse is that stuffing code into the if-block
> bloats the code so much as to frustrate lookahead I-stream caching
> of the normal "branch taken and return 0" path:
>
> if (mp->ma_used > n_used && mp->ma_fill*3 >= (mp->ma_mask+1)*2) {
> if (dictresize(mp, mp->ma_used*2) != 0)
> return -1;
> }
> return 0;
>
> Rewriting as
>
> if (mp->ma_used <= n_used || mp->ma_fill*3 < (mp->ma_mask+1)*2)
> return 0;
>
> return dictresize(mp, mp->ma_used*2) ? -1 : 0;
That last line might as well be
return dictresize(mp, mp->ma_used*2); /* Or *4, per Raymond */
Which reminds me, there are two other places where dictresize() is
called; shouldn't those be changed to the new fill factor?
All in ll I think I'm mildly in favor of this change.
--Guido van Rossum (home page: http://www.python.org/~guido/)