mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 565461: Implement nsTArray::operator==. r=bsmedberg
This commit is contained in:
parent
3736c87ff8
commit
30bb6770cb
@ -298,6 +298,21 @@ class nsTArray : public nsTArray_base {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Return true if this array has the same length and the same
|
||||
// elements as |other|.
|
||||
bool operator==(const self_type& other) const {
|
||||
size_type len = Length();
|
||||
if (len != other.Length())
|
||||
return false;
|
||||
|
||||
// XXX std::equal would be as fast or faster here
|
||||
for (index_type i = 0; i < len; ++i)
|
||||
if (!(operator[](i) == other[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessor methods
|
||||
//
|
||||
|
@ -68,6 +68,9 @@ static PRBool test_basic_array(ElementType *data,
|
||||
if (ary.Length() != dataLen) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (!(ary == ary)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
PRUint32 i;
|
||||
for (i = 0; i < ary.Length(); ++i) {
|
||||
if (ary[i] != data[i])
|
||||
@ -98,6 +101,9 @@ static PRBool test_basic_array(ElementType *data,
|
||||
if (ary[i] == ary[i - 1])
|
||||
ary.RemoveElementAt(i);
|
||||
}
|
||||
if (!(ary == ary)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
for (i = 0; i < ary.Length(); ++i) {
|
||||
if (ary.BinaryIndexOf(ary[i]) != i)
|
||||
return PR_FALSE;
|
||||
@ -108,10 +114,14 @@ static PRBool test_basic_array(ElementType *data,
|
||||
ary.RemoveElement(data[dataLen / 2]);
|
||||
if (ary.Length() != (oldLen - 1))
|
||||
return PR_FALSE;
|
||||
if (!(ary == ary))
|
||||
return PR_FALSE;
|
||||
|
||||
PRUint32 index = ary.Length() / 2;
|
||||
if (!ary.InsertElementAt(index, extra))
|
||||
return PR_FALSE;
|
||||
if (!(ary == ary))
|
||||
return PR_FALSE;
|
||||
if (ary[index] != extra)
|
||||
return PR_FALSE;
|
||||
if (ary.IndexOf(extra) == PR_UINT32_MAX)
|
||||
@ -125,6 +135,8 @@ static PRBool test_basic_array(ElementType *data,
|
||||
return PR_FALSE;
|
||||
|
||||
nsTArray<ElementType> copy(ary);
|
||||
if (!(ary == copy))
|
||||
return PR_FALSE;
|
||||
for (i = 0; i < copy.Length(); ++i) {
|
||||
if (ary[i] != copy[i])
|
||||
return PR_FALSE;
|
||||
@ -140,11 +152,17 @@ static PRBool test_basic_array(ElementType *data,
|
||||
ary.Clear();
|
||||
if (!ary.IsEmpty() || ary.Elements() == nsnull)
|
||||
return PR_FALSE;
|
||||
if (!(ary == nsTArray<ElementType>()))
|
||||
return PR_FALSE;
|
||||
if (ary == copy)
|
||||
return PR_FALSE;
|
||||
if (ary.SafeElementAt(0, extra) != extra ||
|
||||
ary.SafeElementAt(10, extra) != extra)
|
||||
return PR_FALSE;
|
||||
|
||||
ary = copy;
|
||||
if (!(ary == copy))
|
||||
return PR_FALSE;
|
||||
for (i = 0; i < copy.Length(); ++i) {
|
||||
if (ary[i] != copy[i])
|
||||
return PR_FALSE;
|
||||
@ -152,6 +170,8 @@ static PRBool test_basic_array(ElementType *data,
|
||||
|
||||
if (!ary.InsertElementsAt(0, copy))
|
||||
return PR_FALSE;
|
||||
if (ary == copy)
|
||||
return PR_FALSE;
|
||||
ary.RemoveElementsAt(0, copy.Length());
|
||||
for (i = 0; i < copy.Length(); ++i) {
|
||||
if (ary[i] != copy[i])
|
||||
|
Loading…
Reference in New Issue
Block a user