[webkit-dev] WebCore/platform directory

Maciej Stachowiak mjs at apple.com
Thu Dec 7 17:34:33 PST 2006


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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/webkit-dev/attachments/20061207/49a8160f/attachment.html


More information about the webkit-dev mailing list