Changes between Version 2 and Version 3 of AnalyzingBuildPerformance


Ignore:
Timestamp:
Oct 7, 2021, 12:24:32 PM (3 years ago)
Author:
jer.noble@apple.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AnalyzingBuildPerformance

    v2 v3  
    5656C++ class members must be fully defined, so e.g. consider using `UniqueRef<MyClass>`, and forward-declaring `MyClass`, instead of including `MyClass.h`.
    5757
    58 C++ function parameters and return values do not need to be fully defined, and can be forward-declared. So e.g. if `MyClass` function parameter or return value, consider forward-declaring `MyClass`, instead of including `MyClass.h`.
     58C++ function parameters and return values do not need to be fully defined, and can be forward-declared. So e.g. if a method in your class uses `MyClass` as function parameter or return value, consider forward-declaring `MyClass`, instead of including `MyClass.h`.
    5959
    6060C++ virtual functions are rarely able to be inlined, even if decorated with `inline`, so avoid inline definitions of virtual functions. So e.g. if defining a virtual base class method that returns a `Ref<MyClass>`, put the default implementation inside the class implementation file.
     61
     62Bad:
     63{{{
     64#!c++
     65// MyClass.h
     66#include "YourClass.h"
     67class MyClass {
     68public:
     69    void passByValue(YourClass);
     70    void passByReference(const YourClass&);
     71    YourClass getByValue();
     72    virtual std::unique_ptr<YourClass> createUnique() { return nullptr; }
     73};
     74}}}
     75
     76Good:
     77{{{
     78#!c++
     79// MyClass.h
     80class YourClass;
     81
     82class MyClass {
     83public:
     84    void passByValue(YourClass);
     85    void passByReference(const YourClass&);
     86    YourClass getByValue();
     87    virtual std::unique_ptr<YourClass> createUnique();
     88};
     89
     90// MyClass.cpp
     91#include "YourClass.h"
     92std::unique_ptr<YourClass> MyClass::createUnique()
     93{
     94    return nullptr;
     95}
     96}}}
     97
    6198
    6299==== Avoid class-scoped enums ====
     
    115152class MyClass {
    116153public:
    117     YourClass& yourClassGetFoo() { return YourClass::foo(); }
     154    YourClass getFoo() { return YourClass::foo(); }
    118155};
    119156}}}
     
    123160#!c++
    124161// MyClass.h
     162class YourClass;
     163
    125164class MyClass {
    126165public:
    127     inline YourClass& yourClassGetFoo();
     166    inline YourClass getFoo();
    128167};
    129168
    130169// MyClassInlines.h
    131 inline YourClass& MyClass::yourClassGetFoo() { return YourClass::foo(); }
     170#include "YourClass.h"
     171inline YourClass& MyClass::getFoo() { return YourClass::foo(); }
    132172}}}