From e3472c1c99fd7fa6dfb07014f65a710e05bd3d87 Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 26 Mar 2020 11:04:58 +0800 Subject: [PATCH] ble_mesh: Optimize net_buf_simple routines [Zephyr] Use sys_put_xyz() helpers instead of memcpy() whenever possible. This brings in straight-line inline code for pushes and adds of known, small sizes. --- .../bt/esp_ble_mesh/mesh_common/mesh_buf.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c b/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c index 356536e631..01b6300e12 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c @@ -72,16 +72,14 @@ void net_buf_simple_add_le16(struct net_buf_simple *buf, u16_t val) { NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - val = sys_cpu_to_le16(val); - memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val)); + sys_put_le16(val, net_buf_simple_add(buf, sizeof(val))); } void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val) { NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - val = sys_cpu_to_be16(val); - memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val)); + sys_put_be16(val, net_buf_simple_add(buf, sizeof(val))); } void net_buf_simple_add_le24(struct net_buf_simple *buf, u32_t val) @@ -102,16 +100,14 @@ void net_buf_simple_add_le32(struct net_buf_simple *buf, u32_t val) { NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - val = sys_cpu_to_le32(val); - memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val)); + sys_put_le32(val, net_buf_simple_add(buf, sizeof(val))); } void net_buf_simple_add_be32(struct net_buf_simple *buf, u32_t val) { NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - val = sys_cpu_to_be32(val); - memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val)); + sys_put_be32(val, net_buf_simple_add(buf, sizeof(val))); } void net_buf_simple_add_le48(struct net_buf_simple *buf, u64_t val) @@ -157,16 +153,14 @@ void net_buf_simple_push_le16(struct net_buf_simple *buf, u16_t val) { NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - val = sys_cpu_to_le16(val); - memcpy(net_buf_simple_push(buf, sizeof(val)), &val, sizeof(val)); + sys_put_le16(val, net_buf_simple_push(buf, sizeof(val))); } void net_buf_simple_push_be16(struct net_buf_simple *buf, u16_t val) { NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val); - val = sys_cpu_to_be16(val); - memcpy(net_buf_simple_push(buf, sizeof(val)), &val, sizeof(val)); + sys_put_be16(val, net_buf_simple_push(buf, sizeof(val))); } void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val)