Changes between Version 3 and Version 4 of AnalyzingBuildPerformance


Ignore:
Timestamp:
Oct 12, 2021 10:00:30 AM (13 days ago)
Author:
jer.noble@apple.com
Comment:

Add section on inlined virtual functions.

Legend:

Unmodified
Added
Removed
Modified
  • AnalyzingBuildPerformance

    v3 v4  
    171171inline YourClass& MyClass::getFoo() { return YourClass::foo(); }
    172172}}}
     173
     174==== Avoid Virtual Inlines ====
     175
     176Virtual functions will almost never gain any benefit from being inlined (unless callers cast the function itself, e.g.: `foo->Derived::bar()` instead of `foo->bar()`, which is a very uncommon practice). If a virtual function definition in a header file requires including an external header, consider moving the definition into the implementation file. E.g.:
     177
     178Bad:
     179{{{
     180#!c++
     181// MyClass.h
     182#include "YourClass.h"
     183class MyClass final : public BaseClass {
     184public:
     185    void doFoo() final { m_yourClass->doFoo(); }
     186
     187private:
     188    Ref<YourClass> m_yourClass;
     189};
     190}}}
     191
     192Good:
     193{{{
     194#!c++
     195// MyClass.h
     196class MyClass final : public BaseClass {
     197public:
     198    void doFoo() final;
     199
     200private:
     201    Ref<YourClass> m_yourClass;
     202};
     203
     204// MyClass.cpp
     205#include "MyClass.h"
     206#include "YourClass.h"
     207void MyClass::doFoo() { m_yourClass->doFoo(); }
     208}}}