Bug 363767. Add AppendElements() API (that appends empty elements) to nsTArray. r=sicking,sr=darin
git-svn-id: svn://10.0.0.236/trunk@217103 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
bb74327ee2
commit
f50a7d874f
@ -519,16 +519,26 @@ class nsTArray : public nsTArray_base {
|
||||
return AppendElements(&item, 1);
|
||||
}
|
||||
|
||||
// Append new elements without copy-constructing. This is useful to avoid
|
||||
// temporaries.
|
||||
// @return A pointer to the newly appended elements, or null on OOM.
|
||||
elem_type *AppendElements(size_type count) {
|
||||
if (!EnsureCapacity(Length() + count, sizeof(elem_type)))
|
||||
return nsnull;
|
||||
elem_type *elems = Elements() + Length();
|
||||
size_type i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
elem_traits::Construct(elems + i);
|
||||
}
|
||||
IncrementLength(count);
|
||||
return elems;
|
||||
}
|
||||
|
||||
// Append a new element without copy-constructing. This is useful to avoid
|
||||
// temporaries.
|
||||
// @return A pointer to the newly appended element, or null on OOM.
|
||||
elem_type *AppendElement() {
|
||||
if (!EnsureCapacity(Length() + 1, sizeof(elem_type)))
|
||||
return nsnull;
|
||||
elem_type *elem = Elements() + Length();
|
||||
elem_traits::Construct(elem);
|
||||
IncrementLength(1);
|
||||
return elem;
|
||||
return AppendElements(1);
|
||||
}
|
||||
|
||||
// This method removes a range of elements from this array.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user