Yeah, the d-pointer pattern definitely has its costs as well. I think it makes
sense to optimize particular platforms with #ifdefs. The goal, I think, should
be to make sure that things are extensible properly for platform ports w/o
requiring each platform to go that #ifdef route. For example, you could
declare the "d" in an #else section if the MAC platform version were entirely
implemented w/o use of d-pointer.
-- morgan
----- Original Message ----
From: Maciej Stachowiak <[EMAIL PROTECTED]>
To: Morgan L <[EMAIL PROTECTED]>
Cc:
Sebastien Roret <[EMAIL PROTECTED]>; [email protected]
Sent: Thursday, December 7, 2006 5:34:33 PM
Subject: Re: [webkit-dev] WebCore/platform directory
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
____________________________________________________________________________________
Have a burning question?
Go to www.Answers.yahoo.com and get answers from real people who know.
_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-dev