From f1828e6b0adb87bf0b99d3cfeeafbb76cbc6aab7 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 1 Feb 2016 16:46:53 +0100 Subject: 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. --- apt-pkg/contrib/fileutl.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apt-pkg/contrib') 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) -- cgit v1.2.3