From e91db7b4d2694cd7a1c11b07e979fbbbb5561e99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beat=20K=C3=BCng?= <beat-kueng@gmx.net>
Date: Wed, 7 Nov 2018 09:46:04 +0100
Subject: [PATCH] uORBDeviceNode: move flags from SubscriberData to
 UpdateIntervalData

As there is only one bit used in 'flags', and it is only used in case
update_interval is not null, we can move the bit to UpdateIntervalData.

The size of UpdateIntervalData does not increase (on 32 bit).

Reduces RAM usage by 3.6KB (tested on a Pixracer).
---
 src/modules/uORB/uORBDeviceNode.hpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/modules/uORB/uORBDeviceNode.hpp b/src/modules/uORB/uORBDeviceNode.hpp
index cd1070ab54..56128c8c09 100644
--- a/src/modules/uORB/uORBDeviceNode.hpp
+++ b/src/modules/uORB/uORBDeviceNode.hpp
@@ -184,21 +184,23 @@ protected:
 
 private:
 	struct UpdateIntervalData {
-		unsigned  interval; /**< if nonzero minimum interval between updates */
 		struct hrt_call update_call;  /**< deferred wakeup call if update_period is nonzero */
 #ifndef __PX4_NUTTX
 		uint64_t last_update; /**< time at which the last update was provided, used when update_interval is nonzero */
 #endif
+		unsigned  interval; /**< if nonzero minimum interval between updates */
+		bool update_reported;
 	};
 	struct SubscriberData {
 		~SubscriberData() { if (update_interval) { delete (update_interval); } }
 
 		unsigned  generation; /**< last generation the subscriber has seen */
-		int   flags; /**< lowest 8 bits: priority of publisher, 9. bit: update_reported bit */
 		UpdateIntervalData *update_interval; /**< if null, no update interval */
 
-		bool update_reported() const { return flags & (1 << 8); }
-		void set_update_reported(bool update_reported_flag) { flags = (flags & ~(1 << 8)) | (((int)update_reported_flag) << 8); }
+		// these flags are only used if update_interval != null
+		bool update_reported() const { return update_interval ? update_interval->update_reported : false; }
+		void set_update_reported(bool update_reported_flag)
+		{ if (update_interval) { update_interval->update_reported = update_reported_flag; } }
 	};
 
 	const struct orb_metadata *_meta; /**< object metadata information */
-- 
GitLab