#include "serialise.hh" #include "util.hh" #include #include namespace nix { BufferedSink::~BufferedSink() { /* We can't call flush() here, because C++ for some insane reason doesn't allow you to call virtual methods from a destructor. */ assert(!bufPos); delete[] buffer; } void BufferedSink::operator () (const unsigned char * data, size_t len) { if (!buffer) buffer = new unsigned char[bufSize]; while (len) { /* Optimisation: bypass the buffer if the data exceeds the buffer size. */ if (bufPos + len >= bufSize) { flush(); write(data, len); break; } /* Otherwise, copy the bytes to the buffer. Flush the buffer when it's full. */ size_t n = bufPos + len > bufSize ? bufSize - bufPos : len; memcpy(buffer + bufPos, data, n); data += n; bufPos += n; len -= n; if (bufPos == bufSize) flush(); } } void BufferedSink::flush() { if (bufPos == 0) return;
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2019-10-27 08:34:36 +0100
committerRicardo Wurmus <rekado@elephly.net>2019-10-27 08:34:36 +0100
commitb8731d03a7caf8a2594eca90cbb509cc860994ee (patch)
tree86d368bc25398a4c360eee74aba769557b6e89c6 /tests/guix-daemon.sh
parent9538014aa9c63f9cc4ea086b0243e0813f119e1c (diff)
downloadguix-b8731d03a7caf8a2594eca90cbb509cc860994ee.tar.gz
guix-b8731d03a7caf8a2594eca90cbb509cc860994ee.zip
gnu: r-mgcv: Update to 1.8-30.
* gnu/packages/statistics.scm (r-mgcv): Update to 1.8-30.
ze_t readString(unsigned char * buf, size_t max, Source & source) { size_t len = readInt(source); if (len > max) throw Error("string is too long"); source(buf, len); readPadding(len, source); return len; } string readString(Source & source) { size_t len = readInt(source); unsigned char * buf = new unsigned char[len]; AutoDeleteArray d(buf); source(buf, len); readPadding(len, source); return string((char *) buf, len); } template T readStrings(Source & source) { unsigned int count = readInt(source); T ss; while (count--) ss.insert(ss.end(), readString(source)); return ss; } template Paths readStrings(Source & source); template PathSet readStrings(Source & source); void StringSink::operator () (const unsigned char * data, size_t len) { static bool warned = false; if (!warned && s.size() > threshold) { warnLargeDump(); warned = true; } s.append((const char *) data, len); } }