From 7fd83ebd39d7bbaf23ef5718c730f286b4feaecd Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 28 Jul 2021 15:21:03 -0400 Subject: [PATCH] Fix SkTLList::popTail Change-Id: Id3e4d10456be6e0e0329600f05641034f3ffdb8b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/434336 Commit-Queue: Brian Osman Commit-Queue: Mike Reed Auto-Submit: Brian Osman Reviewed-by: Mike Reed --- src/core/SkTLList.h | 2 +- tests/LListTest.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/SkTLList.h b/src/core/SkTLList.h index 6412aefdd6..65f72a6fdc 100644 --- a/src/core/SkTLList.h +++ b/src/core/SkTLList.h @@ -123,7 +123,7 @@ public: void popTail() { this->validate(); - Node* node = fList.head(); + Node* node = fList.tail(); if (node) { this->removeNode(node); } diff --git a/tests/LListTest.cpp b/tests/LListTest.cpp index 2ed880dfb9..719d5a3aac 100644 --- a/tests/LListTest.cpp +++ b/tests/LListTest.cpp @@ -214,6 +214,21 @@ template static void test_tllist(skiatest::Reporter* reporter) list2.reset(); REPORTER_ASSERT(reporter, list1.isEmpty() && list2.isEmpty()); + list1.addToTail(ListElement(1)); + list1.addToTail(ListElement(2)); + list1.addToTail(ListElement(4)); + list1.addToTail(ListElement(8)); + list1.popHead(); + REPORTER_ASSERT(reporter, list1.count() == 3); + REPORTER_ASSERT(reporter, *list1.head() == ListElement(2)); + REPORTER_ASSERT(reporter, *list1.tail() == ListElement(8)); + list1.popTail(); + REPORTER_ASSERT(reporter, list1.count() == 2); + REPORTER_ASSERT(reporter, *list1.head() == ListElement(2)); + REPORTER_ASSERT(reporter, *list1.tail() == ListElement(4)); + + list1.reset(); + // randomly perform insertions and deletions on a list and perform tests int count = 0; for (int j = 0; j < 100; ++j) {