diff mbox

[LEDE-DEV,ubus] ubusd_monitor: alloc & free the buffer outside of the loop

Message ID 1499260366-6285-1-git-send-email-alexandru.ardelean@riverbed.com
State Rejected
Headers show

Commit Message

Alexandru Ardelean July 5, 2017, 1:12 p.m. UTC
From: Alexandru Ardelean <ardeleanalex@gmail.com>

Should save a few cycles, since the data that's
being changed is only the seq number.
And the `ub` is always created as shared.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
---
 ubusd_monitor.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Alexandru Ardelean July 5, 2017, 1:15 p.m. UTC | #1
On Wed, Jul 5, 2017 at 4:12 PM, Alexandru Ardelean
<ardeleanalex@gmail.com> wrote:
> From: Alexandru Ardelean <ardeleanalex@gmail.com>
>
> Should save a few cycles, since the data that's
> being changed is only the seq number.
> And the `ub` is always created as shared.
>
> Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> ---
>  ubusd_monitor.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/ubusd_monitor.c b/ubusd_monitor.c
> index a192206..fcbc6a4 100644
> --- a/ubusd_monitor.c
> +++ b/ubusd_monitor.c
> @@ -72,13 +72,15 @@ ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send
>         blob_put_int8(&mb, UBUS_MONITOR_SEND, send);
>         blob_put(&mb, UBUS_MONITOR_DATA, blob_data(ub->data), blob_len(ub->data));
>
> +       ub = ubus_msg_new(mb.head, blob_raw_len(mb.head), true);
> +       ub->hdr.type = UBUS_MSG_MONITOR;
> +
>         list_for_each_entry(m, &monitors, list) {
> -               ub = ubus_msg_new(mb.head, blob_raw_len(mb.head), true);
> -               ub->hdr.type = UBUS_MSG_MONITOR;
>                 ub->hdr.seq = ++m->seq;
>                 ubus_msg_send(m->cl, ub);
> -               ubus_msg_free(ub);

Urgs...
Disregard this patch.
It's based on a unsubmitted patch from my local tree.

>         }
> +
> +       ubus_msg_free(ub);
>  }
>
>  static int
> --
> 2.7.4
>
diff mbox

Patch

diff --git a/ubusd_monitor.c b/ubusd_monitor.c
index a192206..fcbc6a4 100644
--- a/ubusd_monitor.c
+++ b/ubusd_monitor.c
@@ -72,13 +72,15 @@  ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send
 	blob_put_int8(&mb, UBUS_MONITOR_SEND, send);
 	blob_put(&mb, UBUS_MONITOR_DATA, blob_data(ub->data), blob_len(ub->data));
 
+	ub = ubus_msg_new(mb.head, blob_raw_len(mb.head), true);
+	ub->hdr.type = UBUS_MSG_MONITOR;
+
 	list_for_each_entry(m, &monitors, list) {
-		ub = ubus_msg_new(mb.head, blob_raw_len(mb.head), true);
-		ub->hdr.type = UBUS_MSG_MONITOR;
 		ub->hdr.seq = ++m->seq;
 		ubus_msg_send(m->cl, ub);
-		ubus_msg_free(ub);
 	}
+
+	ubus_msg_free(ub);
 }
 
 static int