-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Reduce moc Parse Time by Forward-Declaring Vehicle in Headers
Background
Vehicle.h is 1454 lines and is included by 9 headers that each trigger a moc run.
Since moc must parse the entire translation unit including all transitive includes, each
of these headers pays the full cost of parsing Vehicle.h even when only pointer-level
access is needed. Replacing the full include with a forward declaration in eligible
headers will meaningfully reduce moc parse time.
Immediate Wins — Headers That Can Forward-Declare Vehicle Today
These headers only use Vehicle at the pointer level and have no nested type access.
The full #include "Vehicle.h" can be replaced with class Vehicle; and the include
moved to the corresponding .cpp file.
| Header | Usage |
|---|---|
src/Camera/QGCCameraManager.h |
Vehicle*, QPointer<Vehicle> — no nested type access |
src/QmlControls/FactValueGrid.h |
Vehicle* in members, signals, parameters — no nested type access |
Blocked — Requires Vehicle Refactoring First
The following headers access nested enum or constant types defined inside Vehicle,
which prevent forward declaration. The full type definition is required to resolve these.
| Header | Blocking Usage |
|---|---|
src/Utilities/StateMachine/States/RequestMessageState.h |
Vehicle::RequestMessageResultHandlerFailureCode_t |
src/Utilities/StateMachine/States/RetryableRequestMessageState.h |
Vehicle::RequestMessageResultHandlerFailureCode_t |
src/Vehicle/Actuators/ActuatorActions.h |
Vehicle::MavCmdResultFailureCode_t |
src/Vehicle/Actuators/ActuatorTesting.h |
Vehicle::MavCmdResultFailureCode_t |
src/Vehicle/Actuators/MotorAssignment.h |
Vehicle::MavCmdResultFailureCode_t |
src/Vehicle/Autotune.h |
Vehicle::MavCmdResultFailureCode_t |
src/FirmwarePlugin/FirmwarePlugin.h |
Vehicle::versionNotSetValue |
Recommended Fix for Blocked Headers
Extract the following from the Vehicle class into a new lightweight VehicleTypes.h header:
MavCmdResultFailureCode_tRequestMessageResultHandlerFailureCode_tversionNotSetValue
All 7 blocked headers can then include only VehicleTypes.h and forward-declare
Vehicle, avoiding the full 1454-line parse for each of their moc runs.
Steps
- Create
src/Vehicle/VehicleTypes.hcontaining the extracted enums/constants - Update
Vehicle.hto includeVehicleTypes.h(preserving existing behaviour) - Replace
#include "Vehicle.h"withclass Vehicle;inQGCCameraManager.handFactValueGrid.h - Replace
#include "Vehicle.h"with#include "VehicleTypes.h"+class Vehicle;in the 7 blocked headers - Add
#include "Vehicle.h"to the corresponding.cppfiles where the full type is needed