Modbus

Parents cadd89d14ca5
Children e319814f1c17
optimization: normalize buffer when it becomes empty after data purge
  • +3 -3
    mb_ds_util.h
  • --- a/mb_ds_util.h Sun Jun 06 22:40:06 2021 +0100
    +++ b/mb_ds_util.h Sun Jun 06 22:52:40 2021 +0100
    @@ -152,10 +152,10 @@
    static inline u8 *lb_data_purge(lb_buf_t *buf, int count) {
    buf->data_start += count + buf->marked_for_purge;
    buf->marked_for_purge = 0;
    - if (buf->data_start > buf->data_end)
    - buf->data_start = buf->data_end;
    - if ((buf->data_end == buf->data_size) || (buf->data_start >= buf->max_data_start))
    + if (buf->data_start >= buf->data_end)
    + buf->data_start = buf->data_end = 0; // no bytes in buffer, might just as well normalize it
    + else if ((buf->data_end == buf->data_size) || (buf->data_start >= buf->max_data_start))
    return lb_normalize(buf);
    return buf->data + buf->data_start;