From 573661de503e627de007100bad0ce7f6226d0774 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 16 Oct 2021 07:35:21 +0800 Subject: [PATCH] common/bl: move bl::prepare_iovs() to .cc file to reduce the compilation time by having a smaller header file. Signed-off-by: Kefu Chai --- src/common/buffer.cc | 28 ++++++++++++++++++++++++++++ src/include/buffer.h | 29 +---------------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 1b36b0543c750..fe9b1e09f373a 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -2030,6 +2030,34 @@ int buffer::list::write_fd(int fd, uint64_t offset) const } #endif +buffer::list::iov_vec_t buffer::list::prepare_iovs() +{ + iov_vec_t iovs; + size_t iovs_i = 0; + size_t index = 0; + uint64_t off = 0; + iovs.resize(_num / IOV_MAX + 1); + iovs[iovs_i].second.resize( + std::min(_num - IOV_MAX * iovs_i, (size_t)IOV_MAX)); + iovs[iovs_i].first.first = off; + iovs[iovs_i].first.second = 0; + for (auto& bp : _buffers) { + if (index == IOV_MAX) { + iovs_i++; + index = 0; + iovs[iovs_i].first.first = off; + iovs[iovs_i].first.second = 0; + iovs[iovs_i].second.resize( + std::min(_num - IOV_MAX * iovs_i, (size_t)IOV_MAX)); + } + iovs[iovs_i].second[index].iov_base = (void*)bp.c_str(); + iovs[iovs_i].second[index++].iov_len = bp.length(); + off += bp.length(); + iovs[iovs_i].first.second += bp.length(); + } + return iovs; +} + __u32 buffer::list::crc32c(__u32 crc) const { int cache_misses = 0; diff --git a/src/include/buffer.h b/src/include/buffer.h index adf56400ecae0..de9ef75b3b2bc 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -1201,34 +1201,7 @@ struct error_code; using iov_vec_t = std::vector, std::vector>>; - iov_vec_t prepare_iovs() - { - iov_vec_t iovs; - size_t iovs_i = 0; - size_t index = 0; - uint64_t off = 0; - iovs.resize(_num / IOV_MAX + 1); - iovs[iovs_i].second.resize( - std::min(_num - IOV_MAX * iovs_i, (size_t)IOV_MAX)); - iovs[iovs_i].first.first = off; - iovs[iovs_i].first.second = 0; - for (auto& bp : _buffers) { - if (index == IOV_MAX) { - iovs_i++; - index = 0; - iovs[iovs_i].first.first = off; - iovs[iovs_i].first.second = 0; - iovs[iovs_i].second.resize( - std::min(_num - IOV_MAX * iovs_i, (size_t)IOV_MAX)); - } - iovs[iovs_i].second[index].iov_base = (void*)bp.c_str(); - iovs[iovs_i].second[index++].iov_len = bp.length(); - off += bp.length(); - iovs[iovs_i].first.second += bp.length(); - } - - return iovs; - } + iov_vec_t prepare_iovs(); uint32_t crc32c(uint32_t crc) const; void invalidate_crc(); -- 2.39.5