From c6964d5af25d4ec7ed9dbe7674dc4e3896b36ead Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 16 四月 2021 16:10:02 +0800
Subject: [PATCH] node remove mq if never registered; refactor.

---
 src/msg.h |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/msg.h b/src/msg.h
index 661d989..10ad0d2 100644
--- a/src/msg.h
+++ b/src/msg.h
@@ -105,27 +105,21 @@
 	bool IsCounted() const { return static_cast<bool>(count_); }
 
 	template <class Body>
-	bool Make(SharedMemory &shm, const BHMsgHead &head, const Body &body)
-	{
-		return Make(shm, Pack(shm, head, body));
-	}
-	template <class Body>
-	bool MakeRC(SharedMemory &shm, const BHMsgHead &head, const Body &body)
+	inline bool MakeRC(SharedMemory &shm, const BHMsgHead &head, const Body &body)
 	{
 		return MakeRC(shm, Pack(shm, head, body));
 	}
-	bool MakeRC(SharedMemory &shm, MsgI &a)
+
+	bool EnableRefCount(SharedMemory &shm);
+
+	template <class Body>
+	inline bool Make(SharedMemory &shm, const BHMsgHead &head, const Body &body)
 	{
-		if (a.IsCounted()) {
-			*this = a;
-			AddRef();
-			return true;
-		} else {
-			void *p = a.ptr_.get();
-			a.ptr_ = 0;
-			return MakeRC(shm, p);
-		}
+		void *p = Pack(shm, head, body);
+		auto NeedRefCount = [&]() { return head.type() == kMsgTypePublish; };
+		return NeedRefCount() ? MakeRC(shm, p) : Make(shm, p);
 	}
+
 	bool ParseHead(BHMsgHead &head) const;
 	template <class Body>
 	bool ParseBody(Body &body) const

--
Gitblit v1.8.0