From f580fcaa674da81d812d8e0a7764fb16b9848153 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sat, 8 Oct 2016 01:12:34 -0400 Subject: [PATCH] refactor in buffer.hpp to not use anonymous namespace in header (#1192) refactor in buffer.hpp to not use anonymous namespace in header --- include/libtorrent/bitfield.hpp | 1 - include/libtorrent/buffer.hpp | 14 +++++--------- src/web_peer_connection.cpp | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 50854c796..39004db44 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -35,7 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/config.hpp" -#include "libtorrent/buffer.hpp" #include "libtorrent/aux_/byteswap.hpp" #include "libtorrent/aux_/ffs.hpp" diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index e436ff221..36442e98e 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -52,13 +52,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - namespace { - inline std::size_t round_up8(std::size_t const v) - { - return (v + 7) & (~std::size_t(0x7)); - } - } - // the buffer is allocated once and cannot be resized. The size() may be // larger than requested, in case the underlying allocator over allocated. In // order to "grow" an allocation, create a new buffer and initialize it by @@ -75,7 +68,10 @@ public: if (size == 0) return; - size = round_up8(size); + // this rounds up the size to be 8 bytes aligned + // it mostly makes sense for platforms without support + // for a variation of "malloc_size()" + size = (size + 7) & (~std::size_t(0x7)); m_begin = static_cast(std::malloc(size)); if (m_begin == nullptr) @@ -108,7 +104,7 @@ public: TORRENT_ASSERT(initialize.size() <= size); if (initialize.size() > 0) { - memcpy(m_begin, initialize.data(), (std::min)(initialize.size(), size)); + std::memcpy(m_begin, initialize.data(), (std::min)(initialize.size(), size)); } } diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index ec85021cf..a06ab1cf8 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -142,7 +142,7 @@ void web_peer_connection::on_connected() // only advertise pieces that are contained within the files we have as // indicated by m_web->have_files AND padfiles! // it's important to include pieces that may overlap many files, as long - // as we have all those files, so instead of starting with a clear bitfied + // as we have all those files, so instead of starting with a clear bitfield // and setting the pieces corresponding to files we have, we do it the // other way around. Start with assuming we have all files, and clear // pieces overlapping with files we *don't* have.