Changes between Version 2 and Version 3 of AnalyzingBuildPerformance
- Timestamp:
- Oct 7, 2021, 12:24:32 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AnalyzingBuildPerformance
v2 v3 56 56 C++ class members must be fully defined, so e.g. consider using `UniqueRef<MyClass>`, and forward-declaring `MyClass`, instead of including `MyClass.h`. 57 57 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`.58 C++ 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`. 59 59 60 60 C++ 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 62 Bad: 63 {{{ 64 #!c++ 65 // MyClass.h 66 #include "YourClass.h" 67 class MyClass { 68 public: 69 void passByValue(YourClass); 70 void passByReference(const YourClass&); 71 YourClass getByValue(); 72 virtual std::unique_ptr<YourClass> createUnique() { return nullptr; } 73 }; 74 }}} 75 76 Good: 77 {{{ 78 #!c++ 79 // MyClass.h 80 class YourClass; 81 82 class MyClass { 83 public: 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" 92 std::unique_ptr<YourClass> MyClass::createUnique() 93 { 94 return nullptr; 95 } 96 }}} 97 61 98 62 99 ==== Avoid class-scoped enums ==== … … 115 152 class MyClass { 116 153 public: 117 YourClass & yourClassGetFoo() { return YourClass::foo(); }154 YourClass getFoo() { return YourClass::foo(); } 118 155 }; 119 156 }}} … … 123 160 #!c++ 124 161 // MyClass.h 162 class YourClass; 163 125 164 class MyClass { 126 165 public: 127 inline YourClass & yourClassGetFoo();166 inline YourClass getFoo(); 128 167 }; 129 168 130 169 // MyClassInlines.h 131 inline YourClass& MyClass::yourClassGetFoo() { return YourClass::foo(); } 170 #include "YourClass.h" 171 inline YourClass& MyClass::getFoo() { return YourClass::foo(); } 132 172 }}}