Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Document limitation of TArray and silence warnings about non-trivia…
…l types being trivially moved
  • Loading branch information
Blzut3 authored and coelckers committed Sep 30, 2019
1 parent ff9715c commit 63f2bf7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/utility/tarray.h
Expand Up @@ -31,6 +31,20 @@
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
** NOTE: TArray takes advantage of the assumption that the contained type is
** able to be trivially moved. The definition of trivially movable by the C++
** standard is more strict than the actual set of types that can be moved with
** memmove. For example, FString uses non-trivial constructors/destructor in
** order to maintain the reference count, but can be "safely" by passed if the
** opaque destructor call is avoided. Similarly types like TArray itself which
** only null the owning pointers when moving which can be skipped if the
** destructor is not called.
**
** It is possible that with LTO TArray could be made safe for non-trivial types,
** but we don't wish to rely on LTO to reach expected performance. The set of
** types which can not be contained by TArray as a result of this choice is
** actually extremely small.
**
*/


Expand Down Expand Up @@ -352,7 +366,8 @@ class TArray
Array[index].~T();
if (index < --Count)
{
memmove (&Array[index], &Array[index+1], sizeof(T)*(Count - index));
// Cast to void to assume trivial move
memmove ((void*)&Array[index], (const void*)&Array[index+1], sizeof(T)*(Count - index));
}
}
}
Expand All @@ -372,7 +387,8 @@ class TArray
Count -= deletecount;
if (index < Count)
{
memmove (&Array[index], &Array[index+deletecount], sizeof(T)*(Count - index));
// Cast to void to assume trivial move
memmove ((void*)&Array[index], (const void*)&Array[index+deletecount], sizeof(T)*(Count - index));
}
}
}
Expand All @@ -394,7 +410,8 @@ class TArray
Resize (Count + 1);

// Now move items from the index and onward out of the way
memmove (&Array[index+1], &Array[index], sizeof(T)*(Count - index - 1));
// Cast to void to assume trivial move
memmove ((void*)&Array[index+1], (const void*)&Array[index], sizeof(T)*(Count - index - 1));

// And put the new element in
::new ((void *)&Array[index]) T(item);
Expand Down

0 comments on commit 63f2bf7

Please sign in to comment.