On Mon, Aug 19, 2013 at 05:15:13PM -0700, Nicholas Nethercote wrote:
> Hi,
> 
> Analysis in https://bugzilla.mozilla.org/show_bug.cgi?id=901132 has
> indicated that jsapi.h is probably responsible for more recompilation
> than any other file in the Mozilla tree -- it gets included in *lots*
> of files, and it gets modified very often, partly because it's so
> large.  (jsfriendapi.h is also bad in this respect.)
> 
> I'm trying to improve this situation in
> https://bugzilla.mozilla.org/show_bug.cgi?id=905017.  It turns out
> that *many* |#include "jsapi.h"| statements are simply not needed.
> They can be replaced by forward declarations of a handful of types,
> e.g.:
> 
>   struct jsid;
>   struct JSContext;
>   class JSObject;
>   namespace JS {
>   template <typename T> class Handle;
>   template <typename T> class MutableHandle;
>   class Value;  // #include js/Value.h (not jsapi.h) if you need the
> *definition*
>   }
> 
> Next time you're thinking of adding a |#include "jsapi.h"| statement,
> please think about whether a forward declaration would suffice -- i.e.
> if you are only using public JS types (i.e. not functions), and only
> using them as pointers, references, or parameters in function
> declarations.  (Forward-declaring JS_PUBLIC_API types is harder;  ask
> me for help if you need to do that.)

Note that here we need to decouple headers and source files. If foo.h
only needs forward declarations for itself, use forward declarations in
foo.h, and if foo.cpp does need more than forward declarations, include
jsapi.h in foo.cpp. Why? Because if you include jsapi.h in foo.h because
foo.cpp needs it, you're also including jsapi.h in anything that
includes foo.h, while they most likely don't need it.

(Note this applies to any types and headers, really, and we're doing a
lot of those #include bar.h in foo.h because Foo have a Bar* member)

Mike
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to