Message132926
| Author |
daniel.urban |
| Recipients |
amaury.forgeotdarc, benjamin.peterson, daniel.urban, georg.brandl, gvanrossum, pwerneck, rodsenra, terry.reedy |
| Date |
2011年04月04日.09:50:45 |
| SpamBayes Score |
6.938894e-15 |
| Marked as misclassified |
No |
| Message-id |
<1301910646.82.0.17268612839.issue1294232@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
The attached patch seems to correct this issue. It contains the test attached yesterday, and it passes now.
I factored out the winner calculation from type_new to a new _PyType_CalculateWinner function, and type_new calls this. I've put the declaration of this function into object.h, so __build_class__ can also call it, instead of using the metaclass of the first base. (Am I correct in thinking that the underscore prefix keeps it out of the public API?)
A slight problem may be, that in some cases this function will be called twice. But it is quite simple, so I don't think it matters much:
Without patch:
$ ./python -m timeit -- "class A(type): pass
class B: pass
class C(metaclass=A): pass
class D(B, C): pass
"
10000 loops, best of 3: 371 usec per loop
With patch:
$ ./python -m timeit -- "class A(type): pass
class B: pass
class C(metaclass=A): pass
class D(B, C): pass
"
10000 loops, best of 3: 381 usec per loop
(Note, that I generated the patch with hg extdiff, because the output of hg qdiff was much more unreadable than simple diff. I can provide an equivalent patch generated by hg if needed.) |
|