Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: src/pdf/SkSinglyLinkedList.h

Issue 1955033002: SkAdvancedTypefaceMetrics: improve robustness (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-05-06 (Friday) 09:17:03 EDT Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #ifndef SkSinglyLinkedList_DEFINED 7 #ifndef SkSinglyLinkedList_DEFINED
8 #define SkSinglyLinkedList_DEFINED 8 #define SkSinglyLinkedList_DEFINED
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "SkTypes.h" 12 #include "SkTypes.h"
13 13
14 template <typename T> class SkSinglyLinkedList { 14 template <typename T> class SkSinglyLinkedList {
15 struct Node; 15 struct Node;
16 public: 16 public:
17 SkSinglyLinkedList() : fHead(nullptr), fTail(nullptr) {} 17 SkSinglyLinkedList() : fHead(nullptr), fTail(nullptr) {}
18 ~SkSinglyLinkedList() { this->reset(); } 18 ~SkSinglyLinkedList() { this->reset(); }
19 void reset() { 19 void reset() {
20 SkASSERT(fHead != nullptr || nullptr == fTail); 20 SkASSERT(fHead != nullptr || nullptr == fTail);
21 // Use a while loop rather than recursion to avoid stack overflow.
21 Node* node = fHead; 22 Node* node = fHead;
22 while (node) { 23 while (node) {
23 Node* next = node->fNext; 24 Node* next = node->fNext;
24 SkASSERT(next != nullptr || node == fTail); 25 SkASSERT(next != nullptr || node == fTail);
25 delete node; 26 delete node;
26 node = next; 27 node = next;
27 } 28 }
28 fHead = nullptr; 29 fHead = nullptr;
29 fTail = nullptr; 30 fTail = nullptr;
30 } 31 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 Node* fNext; 87 Node* fNext;
87 template <class... Args> 88 template <class... Args>
88 Node(Args&&... args) : fData(std::forward<Args>(args)...), fNext(nullptr ) {} 89 Node(Args&&... args) : fData(std::forward<Args>(args)...), fNext(nullptr ) {}
89 }; 90 };
90 Node* fHead; 91 Node* fHead;
91 Node* fTail; 92 Node* fTail;
92 SkSinglyLinkedList(const SkSinglyLinkedList<T>&) = delete; 93 SkSinglyLinkedList(const SkSinglyLinkedList<T>&) = delete;
93 SkSinglyLinkedList& operator=(const SkSinglyLinkedList<T>&) = delete; 94 SkSinglyLinkedList& operator=(const SkSinglyLinkedList<T>&) = delete;
94 }; 95 };
95 #endif // SkSinglyLinkedList_DEFINED 96 #endif // SkSinglyLinkedList_DEFINED
OLDNEW
« src/core/SkAdvancedTypefaceMetrics.h ('K') | « src/core/SkAdvancedTypefaceMetrics.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698