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.
This commit is contained in:
lly 2020-03-26 11:04:58 +08:00
parent 175109d196
commit e3472c1c99

View file

@ -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)