summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-02-01 16:46:53 +0100
committerJulian Andres Klode <jak@debian.org>2016-02-01 16:50:48 +0100
commitf1828e6b0adb87bf0b99d3cfeeafbb76cbc6aab7 (patch)
tree797c8f8665ec8bef7bb26fffb0ac1ebe445ba933 /apt-pkg/contrib/fileutl.cc
parent070ed1c9147c092c1f944afd1c17c51f651a5c39 (diff)
Do not buffer writes larger than the buffer if possible
It makes no sense to split a large block into multiple small blocks, so when we have the chance to write them unbuffered, do so.
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index d95748aa6..8c50874dc 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1260,6 +1260,12 @@ public:
}
virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) override
{
+ // Optimisation: If the buffer is empty and we have more to write than
+ // would fit in the buffer (or equal number of bytes), write directly.
+ if (writebuffer.empty() == true && Size >= writebuffer.free())
+ return wrapped->InternalWrite(From, Size);
+
+ // Write as much into the buffer as possible and then flush if needed
auto written = writebuffer.write(From, Size);
if (writebuffer.full() && InternalFlush() == false)