Small optimization to Metacube output.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Apr 2013 14:39:20 +0000 (16:39 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Apr 2013 14:39:20 +0000 (16:39 +0200)
stream.cpp

index 17b5949..ae31308 100644 (file)
@@ -206,9 +206,20 @@ void Stream::add_data_deferred(const char *data, size_t bytes)
                hdr.flags = htonl(0);
 
                iovec iov;
-               iov.iov_base = new char[sizeof(hdr)];
+               iov.iov_base = new char[bytes + sizeof(hdr)];
+               iov.iov_len = bytes + sizeof(hdr);
+
                memcpy(iov.iov_base, &hdr, sizeof(hdr));
-               iov.iov_len = sizeof(hdr);
+               memcpy(reinterpret_cast<char *>(iov.iov_base) + sizeof(hdr), data, bytes);
+
+               queued_data.push_back(iov);
+       } else if (encoding == Stream::STREAM_ENCODING_RAW) {
+               // Just add the data itself.
+               iovec iov;
+               iov.iov_base = new char[bytes];
+               memcpy(iov.iov_base, data, bytes);
+               iov.iov_len = bytes;
+
                queued_data.push_back(iov);
        } else {
                assert(encoding == Stream::STREAM_ENCODING_RAW);