refactor(mavlink): make streams_list constexpr to save flash and RAM (#28439)

The StreamListItem constructor was not constexpr, so the ~100-entry
streams_list was built at boot by 2.3 KB of static-init code into
.bss. Constant-initialise it into .rodata instead.

Saves 1272 bytes of flash and 1088 bytes of RAM on px4_fmu-v6x_default.

Signed-off-by: Balduin <balduin@auterion.com>
Co-authored-by: Balduin <balduin@auterion.com>
This commit is contained in:
Jacob DahlandBalduin authored and GitHub committed 2026-08-28 18:25:41 -06:00
1 parent 55aa0ea75e
commit d3ca991b8e
2 files changed
+4 -3

No files matched your search

+2 -1
View File
@@ -256,7 +256,8 @@ static_assert(41 == ROTATION_MAX, "Keep MAV_SENSOR_ROTATION and PX4 Rotation in
static_assert(MAV_SENSOR_ROTATION_CUSTOM == static_cast<MAV_SENSOR_ORIENTATION>(ROTATION_CUSTOM), "Custom Rotation");
static const StreamListItem streams_list[] = {
// constexpr so the table is emitted into .rodata instead of being built at runtime by static-init code
static constexpr StreamListItem streams_list[] = {
#if defined(HEARTBEAT_HPP)
create_stream_list_item<MavlinkStreamHeartbeat>(),
#endif // HEARTBEAT_HPP
+2 -2
View File
@@ -54,7 +54,7 @@ public:
const char *name;
uint16_t id;
StreamListItem(MavlinkStream * (*inst)(Mavlink *mavlink), const char *_name, uint16_t _id) :
constexpr StreamListItem(MavlinkStream * (*inst)(Mavlink *mavlink), const char *_name, uint16_t _id) :
new_instance(inst),
name(_name),
id(_id) {}
@@ -64,7 +64,7 @@ public:
};
template <class T>
static StreamListItem create_stream_list_item()
static constexpr StreamListItem create_stream_list_item()
{
return StreamListItem(&T::new_instance, T::get_name_static(), T::get_id_static());
}