aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-07 16:11:00 +0200
committerMax Kellermann <max@duempel.org>2014-08-07 16:11:00 +0200
commit67958f7fa7ae0d9b91fcd6025cda6c6abbecd6da (patch)
treefb8e181fc60bb4c9c25c0319709c149f88ccfd15 /src/util
parentab9c5272741f5c348471cbeee5c9dbe7b562b9fd (diff)
downloadmpd-67958f7fa7ae0d9b91fcd6025cda6c6abbecd6da.tar.gz
mpd-67958f7fa7ae0d9b91fcd6025cda6c6abbecd6da.tar.xz
mpd-67958f7fa7ae0d9b91fcd6025cda6c6abbecd6da.zip
util/{Static,Foreign}FifoBuffer: lazy shift
Reduce the number of unnecessary memmove() calls.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/ForeignFifoBuffer.hxx6
-rw-r--r--src/util/StaticFifoBuffer.hxx6
2 files changed, 10 insertions, 2 deletions
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);
}