From 67958f7fa7ae0d9b91fcd6025cda6c6abbecd6da Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 7 Aug 2014 16:11:00 +0200 Subject: util/{Static,Foreign}FifoBuffer: lazy shift Reduce the number of unnecessary memmove() calls. --- src/util/ForeignFifoBuffer.hxx | 6 +++++- src/util/StaticFifoBuffer.hxx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/ForeignFifoBuffer.hxx b/src/util/ForeignFifoBuffer.hxx index 0ebcd6069..b829fb030 100644 --- a/src/util/ForeignFifoBuffer.hxx +++ b/src/util/ForeignFifoBuffer.hxx @@ -147,7 +147,11 @@ public: * When you are finished, call append(). */ Range Write() { - Shift(); + if (IsEmpty()) + Clear(); + else if (tail == capacity) + Shift(); + return Range(data + tail, capacity - tail); } diff --git a/src/util/StaticFifoBuffer.hxx b/src/util/StaticFifoBuffer.hxx index 67645638e..c1b64bb1e 100644 --- a/src/util/StaticFifoBuffer.hxx +++ b/src/util/StaticFifoBuffer.hxx @@ -92,7 +92,11 @@ public: * When you are finished, call append(). */ Range Write() { - Shift(); + if (IsEmpty()) + Clear(); + else if (tail == size) + Shift(); + return Range(data + tail, size - tail); } -- cgit v1.2.3