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

Side by Side Diff: src/core/SkTLList.h

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 years, 3 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
« no previous file with comments | « src/core/SkStream.cpp ('k') | src/core/SkTLS.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 7
8 #ifndef SkTLList_DEFINED 8 #ifndef SkTLList_DEFINED
9 #define SkTLList_DEFINED 9 #define SkTLList_DEFINED
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 sk_free(block); 64 sk_free(block);
65 } 65 }
66 } 66 }
67 } 67 }
68 68
69 T* addToHead(const T& t) { 69 T* addToHead(const T& t) {
70 this->validate(); 70 this->validate();
71 Node* node = this->createNode(); 71 Node* node = this->createNode();
72 fList.addToHead(node); 72 fList.addToHead(node);
73 SkNEW_PLACEMENT_ARGS(node->fObj, T, (t)); 73 new (node->fObj) T(t);
74 this->validate(); 74 this->validate();
75 return reinterpret_cast<T*>(node->fObj); 75 return reinterpret_cast<T*>(node->fObj);
76 } 76 }
77 77
78 T* addToHead() { 78 T* addToHead() {
79 this->validate(); 79 this->validate();
80 Node* node = this->createNode(); 80 Node* node = this->createNode();
81 fList.addToHead(node); 81 fList.addToHead(node);
82 SkNEW_PLACEMENT(node->fObj, T); 82 new (node->fObj) T;
83 this->validate(); 83 this->validate();
84 return reinterpret_cast<T*>(node->fObj); 84 return reinterpret_cast<T*>(node->fObj);
85 } 85 }
86 86
87 T* addToTail(const T& t) { 87 T* addToTail(const T& t) {
88 this->validate(); 88 this->validate();
89 Node* node = this->createNode(); 89 Node* node = this->createNode();
90 fList.addToTail(node); 90 fList.addToTail(node);
91 SkNEW_PLACEMENT_ARGS(node->fObj, T, (t)); 91 new (node->fObj) T(t);
92 this->validate(); 92 this->validate();
93 return reinterpret_cast<T*>(node->fObj); 93 return reinterpret_cast<T*>(node->fObj);
94 } 94 }
95 95
96 T* addToTail() { 96 T* addToTail() {
97 this->validate(); 97 this->validate();
98 Node* node = this->createNode(); 98 Node* node = this->createNode();
99 fList.addToTail(node); 99 fList.addToTail(node);
100 SkNEW_PLACEMENT(node->fObj, T); 100 new (node->fObj) T;
101 this->validate(); 101 this->validate();
102 return reinterpret_cast<T*>(node->fObj); 102 return reinterpret_cast<T*>(node->fObj);
103 } 103 }
104 104
105 /** Adds a new element to the list before the location indicated by the iter ator. If the 105 /** Adds a new element to the list before the location indicated by the iter ator. If the
106 iterator refers to a NULL location then the new element is added at the tail */ 106 iterator refers to a NULL location then the new element is added at the tail */
107 T* addBefore(const T& t, const Iter& location) { 107 T* addBefore(const T& t, const Iter& location) {
108 return SkNEW_PLACEMENT_ARGS(this->internalAddBefore(location), T, (t)); 108 return new (this->internalAddBefore(location)) T(t);
109 } 109 }
110 110
111 /** Adds a new element to the list after the location indicated by the itera tor. If the 111 /** Adds a new element to the list after the location indicated by the itera tor. If the
112 iterator refers to a NULL location then the new element is added at the head */ 112 iterator refers to a NULL location then the new element is added at the head */
113 T* addAfter(const T& t, const Iter& location) { 113 T* addAfter(const T& t, const Iter& location) {
114 return SkNEW_PLACEMENT_ARGS(this->internalAddAfter(location), T, (t)); 114 return new (this->internalAddAfter(location)) T(t);
115 } 115 }
116 116
117 /** Convenience methods for getting an iterator initialized to the head/tail of the list. */ 117 /** Convenience methods for getting an iterator initialized to the head/tail of the list. */
118 Iter headIter() const { return Iter(*this, Iter::kHead_IterStart); } 118 Iter headIter() const { return Iter(*this, Iter::kHead_IterStart); }
119 Iter tailIter() const { return Iter(*this, Iter::kTail_IterStart); } 119 Iter tailIter() const { return Iter(*this, Iter::kTail_IterStart); }
120 120
121 T* head() { return Iter(*this, Iter::kHead_IterStart).get(); } 121 T* head() { return Iter(*this, Iter::kHead_IterStart).get(); }
122 T* tail() { return Iter(*this, Iter::kTail_IterStart).get(); } 122 T* tail() { return Iter(*this, Iter::kTail_IterStart).get(); }
123 const T* head() const { return Iter(*this, Iter::kHead_IterStart).get(); } 123 const T* head() const { return Iter(*this, Iter::kHead_IterStart).get(); }
124 const T* tail() const { return Iter(*this, Iter::kTail_IterStart).get(); } 124 const T* tail() const { return Iter(*this, Iter::kTail_IterStart).get(); }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 size_t blockSize() const { return sizeof(Block) + sizeof(Node) * (fAllocCnt- 1); } 242 size_t blockSize() const { return sizeof(Block) + sizeof(Node) * (fAllocCnt- 1); }
243 243
244 Node* createNode() { 244 Node* createNode() {
245 Node* node = fFreeList.head(); 245 Node* node = fFreeList.head();
246 if (node) { 246 if (node) {
247 fFreeList.remove(node); 247 fFreeList.remove(node);
248 ++node->fBlock->fNodesInUse; 248 ++node->fBlock->fNodesInUse;
249 } else { 249 } else {
250 Block* block = reinterpret_cast<Block*>(sk_malloc_flags(this->blockS ize(), 0)); 250 Block* block = reinterpret_cast<Block*>(sk_malloc_flags(this->blockS ize(), 0));
251 node = &block->fNodes[0]; 251 node = &block->fNodes[0];
252 SkNEW_PLACEMENT(node, Node); 252 new (node) Node;
253 node->fBlock = block; 253 node->fBlock = block;
254 block->fNodesInUse = 1; 254 block->fNodesInUse = 1;
255 for (int i = 1; i < fAllocCnt; ++i) { 255 for (int i = 1; i < fAllocCnt; ++i) {
256 SkNEW_PLACEMENT(block->fNodes + i, Node); 256 new (block->fNodes + i) Node;
257 fFreeList.addToHead(block->fNodes + i); 257 fFreeList.addToHead(block->fNodes + i);
258 block->fNodes[i].fBlock = block; 258 block->fNodes[i].fBlock = block;
259 } 259 }
260 } 260 }
261 ++fCount; 261 ++fCount;
262 return node; 262 return node;
263 } 263 }
264 264
265 void removeNode(Node* node) { 265 void removeNode(Node* node) {
266 SkASSERT(node); 266 SkASSERT(node);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 #define SkNEW_INSERT_IN_LLIST_AFTER(list, location, type_name, args) \ 394 #define SkNEW_INSERT_IN_LLIST_AFTER(list, location, type_name, args) \
395 (new ((list), SkTLList< type_name >::kAfter_Placement, (location)) type_name args) 395 (new ((list), SkTLList< type_name >::kAfter_Placement, (location)) type_name args)
396 396
397 #define SkNEW_INSERT_AT_LLIST_HEAD(list, type_name, args) \ 397 #define SkNEW_INSERT_AT_LLIST_HEAD(list, type_name, args) \
398 SkNEW_INSERT_IN_LLIST_BEFORE((list), (list)->headIter(), type_name, args) 398 SkNEW_INSERT_IN_LLIST_BEFORE((list), (list)->headIter(), type_name, args)
399 399
400 #define SkNEW_INSERT_AT_LLIST_TAIL(list, type_name, args) \ 400 #define SkNEW_INSERT_AT_LLIST_TAIL(list, type_name, args) \
401 SkNEW_INSERT_IN_LLIST_AFTER((list), (list)->tailIter(), type_name, args) 401 SkNEW_INSERT_IN_LLIST_AFTER((list), (list)->tailIter(), type_name, args)
402 402
403 #endif 403 #endif
OLDNEW
« no previous file with comments | « src/core/SkStream.cpp ('k') | src/core/SkTLS.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698