From: Tudor Bosman Date: Thu, 9 May 2013 21:27:56 +0000 (-0700) Subject: convert RecordIO to pwritev X-Git-Tag: v0.22.0~979 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=63b61817c5f63473b5a0f27a21d91a80be22552d;p=folly.git convert RecordIO to pwritev Summary: zero-copy Test Plan: record_io_test Reviewed By: lucian@fb.com FB internal diff: D806813 --- diff --git a/folly/io/RecordIO.cpp b/folly/io/RecordIO.cpp index 5eba9bc7..69bea4de 100644 --- a/folly/io/RecordIO.cpp +++ b/folly/io/RecordIO.cpp @@ -50,17 +50,14 @@ void RecordIOWriter::write(std::unique_ptr buf) { return; // nothing to do } - // TODO(tudorb): Maybe use pwritev, but for now we're copying everything in - // one place. - buf->unshare(); - buf->coalesce(); - DCHECK_EQ(buf->length(), totalLength); + DCHECK_EQ(buf->computeChainDataLength(), totalLength); + auto iov = buf->getIov(); // We're going to write. Reserve space for ourselves. - off_t pos = filePos_.fetch_add(buf->length()); - ssize_t bytes = pwriteFull(file_.fd(), buf->data(), buf->length(), pos); + off_t pos = filePos_.fetch_add(totalLength); + ssize_t bytes = pwritevFull(file_.fd(), iov.data(), iov.size(), pos); checkUnixError(bytes, "pwrite() failed"); - DCHECK_EQ(bytes, buf->length()); + DCHECK_EQ(bytes, totalLength); } RecordIOReader::RecordIOReader(File file, uint32_t fileId)