optimization: normalize buffer when it becomes empty after data purge
authormjsousa <msousa@fe.up.pt>
Sun, 06 Jun 2021 22:52:40 +0100
changeset 16 4f584251c73d
parent 15 cadd89d14ca5
child 17 e319814f1c17
optimization: normalize buffer when it becomes empty after data purge
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;