remove typed_span type

This commit is contained in:
arvidn 2018-11-05 01:23:13 +01:00 committed by Arvid Norberg
parent ef6db120a3
commit 7103b12cb7
11 changed files with 27 additions and 198 deletions

View File

@ -257,7 +257,6 @@ set(libtorrent_aux_include_files
throw
time
torrent_impl
typed_span
unique_ptr
vector
win_crypto_provider

View File

@ -212,7 +212,6 @@ nobase_include_HEADERS = \
aux_/unique_ptr.hpp \
aux_/alloca.hpp \
aux_/throw.hpp \
aux_/typed_span.hpp \
aux_/array.hpp \
aux_/ip_notifier.hpp \
aux_/noexcept_movable.hpp \

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_ALLOCA_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/typed_span.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/aux_/numeric_cast.hpp"
#include <iterator> // for iterator_traits
#include <memory> // for addressof
@ -77,10 +77,10 @@ struct alloca_destructor
#if defined TORRENT_WINDOWS || defined TORRENT_MINGW
#include <malloc.h>
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span<t> v; { \
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::span<t> v; { \
auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::ptrdiff_t>(n); \
auto* TORRENT_ALLOCA_tmp = static_cast<t*>(_alloca(sizeof(t) * static_cast<std::size_t>(TORRENT_ALLOCA_size))); \
v = ::libtorrent::aux::typed_span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
v = ::libtorrent::span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \
} \
::libtorrent::aux::alloca_destructor<t> v##_destructor{v};
@ -88,10 +88,10 @@ struct alloca_destructor
#elif defined TORRENT_BSD
#include <stdlib.h>
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span<t> v; { \
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::span<t> v; { \
auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::ptrdiff_t>(n); \
auto* TORRENT_ALLOCA_tmp = static_cast<t*>(alloca(sizeof(t) * static_cast<std::size_t>(TORRENT_ALLOCA_size))); \
v = ::libtorrent::aux::typed_span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
v = ::libtorrent::span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \
} \
::libtorrent::aux::alloca_destructor<t> v##_destructor{v};
@ -99,10 +99,10 @@ struct alloca_destructor
#else
#include <alloca.h>
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span<t> v; { \
#define TORRENT_ALLOCA(v, t, n) ::libtorrent::span<t> v; { \
auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast<std::ptrdiff_t>(n); \
auto* TORRENT_ALLOCA_tmp = static_cast<t*>(alloca(sizeof(t) * static_cast<std::size_t>(TORRENT_ALLOCA_size))); \
v = ::libtorrent::aux::typed_span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
v = ::libtorrent::span<t>(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \
::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \
} \
::libtorrent::aux::alloca_destructor<t> v##_destructor{v};

View File

@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/fwd.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/aux_/typed_span.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/storage_defs.hpp" // for status_t
#include "libtorrent/session_types.hpp"
@ -57,7 +57,7 @@ namespace aux {
TORRENT_EXTRA_EXPORT int copy_bufs(span<iovec_t const> bufs
, int bytes, span<iovec_t> target);
TORRENT_EXTRA_EXPORT typed_span<iovec_t> advance_bufs(typed_span<iovec_t> bufs, int bytes);
TORRENT_EXTRA_EXPORT span<iovec_t> advance_bufs(span<iovec_t> bufs, int bytes);
TORRENT_EXTRA_EXPORT void clear_bufs(span<iovec_t const> bufs);
// this is a read or write operation so that readwritev() knows

View File

@ -1,169 +0,0 @@
/*
Copyright (c) 2017, Arvid Norberg, Alden Torres
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_TYPED_SPAN_HPP
#define TORRENT_TYPED_SPAN_HPP
#include <type_traits>
#include "libtorrent/units.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/assert.hpp"
namespace libtorrent { namespace aux {
template <typename T, typename IndexType = int>
struct typed_span : span<T>
{
using base = span<T>;
using underlying_index = typename underlying_index_t<IndexType>::type;
using typename span<T>::difference_type;
using typename span<T>::index_type;
// disallow conversions from other index types
template <typename OtherIndex>
typed_span(typed_span<T, OtherIndex> const&) = delete;
typed_span() noexcept = default;
typed_span(typed_span const&) noexcept = default;
typed_span& operator=(typed_span const&) noexcept = default;
template <typename U, typename
= typename std::enable_if<aux::compatible_type<U, T>::value>::type>
typed_span(typed_span<U> const& v) noexcept // NOLINT
: span<T>(v) {}
typed_span(T& p) noexcept : span<T>(p) {} // NOLINT
typed_span(T* p, difference_type const l) noexcept : span<T>(p, l) {} // NOLINT
template <typename U, std::size_t N>
typed_span(std::array<U, N>& arr) noexcept // NOLINT
: span<T>(arr.data(), static_cast<difference_type>(arr.size())) {}
template <typename U, difference_type N>
typed_span(U (&arr)[N]) noexcept // NOLINT
: span<T>(&arr[0], N) {}
// anything with a .data() member function is considered a container
// but only if the value type is compatible with T
template <typename Cont
, typename U = typename std::remove_reference<decltype(*std::declval<Cont>().data())>::type
, typename = typename std::enable_if<aux::compatible_type<U, T>::value>::type>
typed_span(Cont& c) : span<T>(c.data(), c.size())// NOLINT
{}
auto operator[](IndexType idx) const ->
#if TORRENT_AUTO_RETURN_TYPES
decltype(auto)
#else
decltype(this->base::operator[](underlying_index()))
#endif
{
TORRENT_ASSERT(idx >= IndexType(0));
return this->base::operator[](index_type(static_cast<underlying_index>(idx)));
}
IndexType end_index() const
{
TORRENT_ASSERT(this->size() <= difference_type((std::numeric_limits<underlying_index>::max)()));
return IndexType(static_cast<underlying_index>(this->size()));
}
template <typename U = underlying_index, typename Cond
= typename std::enable_if<std::is_signed<U>::value>::type>
typed_span first(underlying_index n) const
{
TORRENT_ASSERT(n >= 0);
auto const s = this->base::first(difference_type(n));
return {s.data(), s.size()};
}
typed_span first(difference_type n) const
{
TORRENT_ASSERT(n <= difference_type((std::numeric_limits<underlying_index>::max)()));
auto const s = this->base::first(n);
return {s.data(), s.size()};
}
template <typename U = underlying_index, typename Cond
= typename std::enable_if<std::is_signed<U>::value>::type>
typed_span last(underlying_index n) const
{
TORRENT_ASSERT(n >= 0);
auto const s = this->base::last(difference_type(n));
return {s.data(), s.size()};
}
typed_span last(difference_type n) const
{
TORRENT_ASSERT(n <= difference_type((std::numeric_limits<underlying_index>::max)()));
auto const s = this->base::last(n);
return {s.data(), s.size()};
}
template <typename U = underlying_index, typename Cond
= typename std::enable_if<std::is_signed<U>::value>::type>
typed_span subspan(underlying_index offset) const
{
TORRENT_ASSERT(offset >= 0);
auto const s = this->base::subspan(index_type(offset));
return {s.data(), s.size()};
}
template <typename U = underlying_index, typename Cond
= typename std::enable_if<std::is_signed<U>::value>::type>
typed_span subspan(underlying_index offset, underlying_index count) const
{
TORRENT_ASSERT(offset >= 0);
TORRENT_ASSERT(count >= 0);
auto const s = this->base::subspan(index_type(offset), difference_type(count));
return {s.data(), s.size()};
}
typed_span subspan(index_type const offset) const
{
TORRENT_ASSERT(offset <= index_type((std::numeric_limits<underlying_index>::max)()));
auto const s = this->base::subspan(offset);
return {s.data(), s.size()};
}
typed_span subspan(index_type const offset, difference_type const count) const
{
TORRENT_ASSERT(offset <= index_type((std::numeric_limits<underlying_index>::max)()));
TORRENT_ASSERT(count <= difference_type((std::numeric_limits<underlying_index>::max)()));
auto const s = this->base::subspan(offset, count);
return {s.data(), s.size()};
}
};
}}
#endif

View File

@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/piece_block.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/aux_/array.hpp"
#include "libtorrent/aux_/typed_span.hpp"
#include "libtorrent/span.hpp"
#include "libtorrent/alert_types.hpp" // for picker_flags_t
#include "libtorrent/download_priority.hpp"
#include "libtorrent/flags.hpp"
@ -465,13 +465,13 @@ namespace libtorrent {
// return the array of block_info objects for a given downloading_piece.
// this array has m_blocks_per_piece elements in it
aux::typed_span<block_info const> blocks_for_piece(downloading_piece const& dp) const;
span<block_info const> blocks_for_piece(downloading_piece const& dp) const;
private:
int num_pad_blocks() const { return m_num_pad_blocks; }
aux::typed_span<block_info> mutable_blocks_for_piece(downloading_piece const& dp);
span<block_info> mutable_blocks_for_piece(downloading_piece const& dp);
std::tuple<bool, bool, int, int> requested_from(
piece_picker::downloading_piece const& p

View File

@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/assert.hpp"
#include "libtorrent/aux_/byteswap.hpp"
#include "libtorrent/aux_/ffs.hpp"
#include "libtorrent/aux_/typed_span.hpp"
#include "libtorrent/span.hpp"
#if TORRENT_USE_IOSTREAM
#include <iosfwd>
@ -58,8 +58,8 @@ namespace libtorrent {
// TODO: find a better place for these functions
namespace aux {
TORRENT_EXTRA_EXPORT void bits_shift_left(typed_span<std::uint32_t> number, int n);
TORRENT_EXTRA_EXPORT void bits_shift_right(typed_span<std::uint32_t> number, int n);
TORRENT_EXTRA_EXPORT void bits_shift_left(span<std::uint32_t> number, int n);
TORRENT_EXTRA_EXPORT void bits_shift_right(span<std::uint32_t> number, int n);
}
// This type holds an N digest or any other kind of N bits

View File

@ -360,7 +360,7 @@ namespace libtorrent {
*zero_prio = int(m_downloads[piece_pos::piece_zero_prio].size());
}
aux::typed_span<piece_picker::block_info> piece_picker::mutable_blocks_for_piece(
span<piece_picker::block_info> piece_picker::mutable_blocks_for_piece(
downloading_piece const& dp)
{
int idx = int(dp.info_idx) * m_blocks_per_piece;
@ -368,7 +368,7 @@ namespace libtorrent {
return { &m_block_info[idx], blocks_in_piece(dp.index) };
}
aux::typed_span<piece_picker::block_info const> piece_picker::blocks_for_piece(
span<piece_picker::block_info const> piece_picker::blocks_for_piece(
downloading_piece const& dp) const
{
return const_cast<piece_picker*>(this)->mutable_blocks_for_piece(dp);

View File

@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/receive_buffer.hpp"
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/aux_/numeric_cast.hpp"
#include "libtorrent/aux_/typed_span.hpp"
#include "libtorrent/span.hpp"
namespace libtorrent {
@ -62,7 +62,7 @@ span<char> receive_buffer::reserve(int const size)
m_watermark = {};
}
return aux::typed_span<char>(m_recv_buffer).subspan(m_recv_end, size);
return span<char>(m_recv_buffer).subspan(m_recv_end, size);
}
void receive_buffer::grow(int const limit)
@ -145,14 +145,14 @@ span<char const> receive_buffer::get() const
}
TORRENT_ASSERT(m_recv_start + m_recv_pos <= int(m_recv_buffer.size()));
return aux::typed_span<char const>(m_recv_buffer).subspan(m_recv_start, m_recv_pos);
return span<char const>(m_recv_buffer).subspan(m_recv_start, m_recv_pos);
}
#if !defined TORRENT_DISABLE_ENCRYPTION
span<char> receive_buffer::mutable_buffer()
{
INVARIANT_CHECK;
return aux::typed_span<char>(m_recv_buffer).subspan(m_recv_start, m_recv_pos);
return span<char>(m_recv_buffer).subspan(m_recv_start, m_recv_pos);
}
span<char> receive_buffer::mutable_buffer(int const bytes)
@ -161,7 +161,7 @@ span<char> receive_buffer::mutable_buffer(int const bytes)
// bytes is the number of bytes we just received, and m_recv_pos has
// already been adjusted for these bytes. The receive pos immediately
// before we received these bytes was (m_recv_pos - bytes)
return aux::typed_span<char>(m_recv_buffer).subspan(m_recv_start + m_recv_pos - bytes, bytes);
return span<char>(m_recv_buffer).subspan(m_recv_start + m_recv_pos - bytes, bytes);
}
#endif

View File

@ -62,11 +62,11 @@ namespace libtorrent {
namespace aux {
void bits_shift_left(typed_span<std::uint32_t> number, int n)
void bits_shift_left(span<std::uint32_t> const number, int n)
{
TORRENT_ASSERT(n >= 0);
int const num_words = n / 32;
int const number_size = number.end_index();
int const number_size = int(number.size());
if (num_words >= number_size)
{
std::memset(number.data(), 0, std::size_t(number.size() * 4));
@ -100,11 +100,11 @@ namespace aux {
}
}
void bits_shift_right(typed_span<std::uint32_t> number, int n)
void bits_shift_right(span<std::uint32_t> const number, int n)
{
TORRENT_ASSERT(n >= 0);
int const num_words = n / 32;
int const number_size = number.end_index();
int const number_size = int(number.size());
if (num_words >= number_size)
{
std::memset(number.data(), 0, std::size_t(number.size() * 4));

View File

@ -63,7 +63,7 @@ namespace libtorrent { namespace aux {
return ret;
}
typed_span<iovec_t> advance_bufs(typed_span<iovec_t> bufs, int const bytes)
span<iovec_t> advance_bufs(span<iovec_t> bufs, int const bytes)
{
TORRENT_ASSERT(bytes >= 0);
std::ptrdiff_t size = 0;