On Dec 7, 2006, at 5:26 PM, Morgan L wrote:
Virtual functions are more expensive than the "Cheshire Cat"
pattern because they add code bloat to each call-site. To call a
virtual function the compiler must generate extra code to
dereference the object's vtable, whereas with a d-pointer approach
that cost exists only once at the site of the implementation.
Moreover, the d-pointer approach allows cross-platform code to be
more easily shared between the ports. The approach breaks down,
however, when header files are heavily #ifdef'd as they are in much
of WebCore today. It seems to me that there is a happy middle
ground to be had :-)
I agree that making the platform dir classes all pure virtual would
be inappropriate. Many of these classes are used quite heavily and
this would be a major performance hit.
However, the d-pointer approach also has its costs, in extra dynamic
memory allocations and extra indirection to access data members.
This is why we usually ifdef platform-specific data members.
However, we can re-examine the approach on a case-by-case basis, and
only use platform-specific inline data members in cases where it
really is performance critical. For classes where there are not that
many instances created, using a d-pointer could certainly make things
simpler.
Regards,
Maciej
_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-dev