Fix SkTArray operator= to work with self assignment
BUG=skia: Change-Id: I2a403a7ccbb87a030757f3e57d2ea53503f72512 Reviewed-on: https://skia-review.googlesource.com/10012 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
dbd11ec106
commit
70131b97f9
@ -59,6 +59,9 @@ public:
|
||||
}
|
||||
|
||||
SkTArray& operator=(const SkTArray& that) {
|
||||
if (this == &that) {
|
||||
return *this;
|
||||
}
|
||||
for (int i = 0; i < fCount; ++i) {
|
||||
fItemArray[i].~T();
|
||||
}
|
||||
@ -69,6 +72,9 @@ public:
|
||||
return *this;
|
||||
}
|
||||
SkTArray& operator=(SkTArray&& that) {
|
||||
if (this == &that) {
|
||||
return *this;
|
||||
}
|
||||
for (int i = 0; i < fCount; ++i) {
|
||||
fItemArray[i].~T();
|
||||
}
|
||||
|
@ -281,6 +281,19 @@ void test_unnecessary_alloc(skiatest::Reporter* reporter) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_self_assignment(skiatest::Reporter* reporter) {
|
||||
SkTArray<int> a;
|
||||
a.push_back(1);
|
||||
REPORTER_ASSERT(reporter, !a.empty());
|
||||
REPORTER_ASSERT(reporter, a.count() == 1);
|
||||
REPORTER_ASSERT(reporter, a[0] == 1);
|
||||
|
||||
a = a;
|
||||
REPORTER_ASSERT(reporter, !a.empty());
|
||||
REPORTER_ASSERT(reporter, a.count() == 1);
|
||||
REPORTER_ASSERT(reporter, a[0] == 1);
|
||||
}
|
||||
|
||||
DEF_TEST(TArray, reporter) {
|
||||
TestTSet_basic<true>(reporter);
|
||||
TestTSet_basic<false>(reporter);
|
||||
@ -296,4 +309,6 @@ DEF_TEST(TArray, reporter) {
|
||||
test_move(reporter);
|
||||
|
||||
test_unnecessary_alloc(reporter);
|
||||
|
||||
test_self_assignment(reporter);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user