Use memcpy and memset instead of per-element copy and zero.

This commit is contained in:
Bartosz Taudul 2019-02-13 02:23:56 +01:00
parent d854998856
commit 40d0c72982

View File

@ -30,13 +30,9 @@ public:
Vector( const Vector& ) = delete; Vector( const Vector& ) = delete;
Vector( Vector&& src ) noexcept Vector( Vector&& src ) noexcept
: m_ptr( src.m_ptr )
, m_size( src.m_size )
, m_capacity( src.m_capacity )
{ {
src.m_ptr = nullptr; memcpy( this, &src, sizeof( Vector<T> ) );
src.m_size = 0; memset( &src, 0, sizeof( Vector<T> ) );
src.m_capacity = 0;
} }
Vector( const T& value ) Vector( const T& value )
@ -65,12 +61,8 @@ public:
Vector& operator=( Vector&& src ) noexcept Vector& operator=( Vector&& src ) noexcept
{ {
delete[] m_ptr; delete[] m_ptr;
m_ptr = src.m_ptr; memcpy( this, &src, sizeof( Vector<T> ) );
m_size = src.m_size; memset( &src, 0, sizeof( Vector<T> ) );
m_capacity = src.m_capacity;
src.m_ptr = nullptr;
src.m_size = 0;
src.m_capacity = 0;
return *this; return *this;
} }