Skip to content

Commit

Permalink
Use move instead of copy in vector::insert() and vector::set_capacity()
Browse files Browse the repository at this point in the history
  • Loading branch information
Wawha committed Nov 6, 2016
1 parent 256c712 commit 0b73b4d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/EASTL/vector.h
Expand Up @@ -890,7 +890,7 @@ namespace eastl
else if(n < (size_type)(mpEnd - mpBegin))
resize(n);

this_type temp(*this); // This is the simplest way to accomplish this,
this_type temp(eastl::move(*this)); // This is the simplest way to accomplish this,
swap(temp); // and it is as efficient as any other.
}
else // Else new capacity > size.
Expand Down Expand Up @@ -1628,16 +1628,16 @@ namespace eastl

if(n < nExtra) // If the inserted values are entirely within initialized memory (i.e. are before mpEnd)...
{
eastl::uninitialized_copy_ptr(mpEnd - n, mpEnd, mpEnd);
eastl::copy_backward(destPosition, mpEnd - n, mpEnd); // We need copy_backward because of potential overlap issues.
eastl::uninitialized_move_ptr(mpEnd - n, mpEnd, mpEnd);
eastl::move_backward(destPosition, mpEnd - n, mpEnd); // We need move_backward because of potential overlap issues.
eastl::copy(first, last, destPosition);
}
else
{
BidirectionalIterator iTemp = first;
eastl::advance(iTemp, nExtra);
eastl::uninitialized_copy_ptr(iTemp, last, mpEnd);
eastl::uninitialized_copy_ptr(destPosition, mpEnd, mpEnd + n - nExtra);
eastl::uninitialized_move_ptr(destPosition, mpEnd, mpEnd + n - nExtra);
eastl::copy_backward(first, iTemp, destPosition + nExtra);
}

Expand Down Expand Up @@ -1702,14 +1702,14 @@ namespace eastl

if(n < nExtra)
{
eastl::uninitialized_copy_ptr(mpEnd - n, mpEnd, mpEnd);
eastl::copy_backward(destPosition, mpEnd - n, mpEnd); // We need copy_backward because of potential overlap issues.
eastl::uninitialized_move_ptr(mpEnd - n, mpEnd, mpEnd);
eastl::move_backward(destPosition, mpEnd - n, mpEnd); // We need move_backward because of potential overlap issues.
eastl::fill(destPosition, destPosition + n, temp);
}
else
{
eastl::uninitialized_fill_n_ptr(mpEnd, n - nExtra, temp);
eastl::uninitialized_copy_ptr(destPosition, mpEnd, mpEnd + n - nExtra);
eastl::uninitialized_move_ptr(destPosition, mpEnd, mpEnd + n - nExtra);
eastl::fill(destPosition, mpEnd, temp);
}

Expand Down

0 comments on commit 0b73b4d

Please sign in to comment.