Bug 517943 - Need a way to append the contents of an nsTArray to another without copying. r=benjamin, sr=dbaron.

This commit is contained in:
Henri Sivonen 2009-09-24 20:26:31 +03:00
Родитель f3428d4d90
Коммит 8b87e97dd6
1 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -654,6 +654,22 @@ class nsTArray : public nsTArray_base {
return AppendElements(1);
}
// Move all elements from another array to the end of this array without
// calling copy constructors or destructors.
// @return A pointer to the newly appended elements, or null on OOM.
template<class Item>
elem_type *MoveElementsFrom(nsTArray<Item>& array) {
NS_PRECONDITION(&array != this, "argument must be different array");
index_type len = Length();
index_type otherLen = array.Length();
if (!EnsureCapacity(len + otherLen, sizeof(elem_type)))
return nsnull;
memcpy(Elements() + len, array.Elements(), otherLen * sizeof(elem_type));
IncrementLength(otherLen);
array.ShiftData(0, otherLen, 0, sizeof(elem_type));
return Elements() + len;
}
// This method removes a range of elements from this array.
// @param start The starting index of the elements to remove.
// @param count The number of elements to remove.