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

Side by Side Diff: dart/runtime/bin/eventhandler.h

Issue 914203002: Add unittest for CircularLinkedList + bugfix (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef BIN_EVENTHANDLER_H_ 5 #ifndef BIN_EVENTHANDLER_H_
6 #define BIN_EVENTHANDLER_H_ 6 #define BIN_EVENTHANDLER_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/dartutils.h" 9 #include "bin/dartutils.h"
10 #include "bin/isolate_data.h" 10 #include "bin/isolate_data.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Insert e as the last element in the list. 143 // Insert e as the last element in the list.
144 e->prev_ = head_->prev_; 144 e->prev_ = head_->prev_;
145 e->next_ = head_; 145 e->next_ = head_;
146 e->prev_->next_ = e; 146 e->prev_->next_ = e;
147 head_->prev_ = e; 147 head_->prev_ = e;
148 return false; 148 return false;
149 } 149 }
150 } 150 }
151 151
152 void RemoveHead() { 152 void RemoveHead() {
153 ASSERT(head_ != NULL);
154
153 Entry* e = head_; 155 Entry* e = head_;
154 if (e->next_ == e) { 156 if (e->next_ == e) {
155 head_ = NULL; 157 head_ = NULL;
156 } else { 158 } else {
157 e->prev_->next_ = e->next_; 159 e->prev_->next_ = e->next_;
158 e->next_->prev_ = e->prev_; 160 e->next_->prev_ = e->prev_;
159 head_ = e->next_; 161 head_ = e->next_;
160 } 162 }
161 delete e; 163 delete e;
162 } 164 }
163 165
164 void Remove(T item) { 166 void Remove(T item) {
165 if (head_ == NULL) { 167 if (head_ == NULL) {
166 return; 168 return;
167 } else if (head_ == head_->next_) { 169 } else if (head_ == head_->next_) {
168 if (head_->t == item) { 170 if (head_->t == item) {
169 delete head_; 171 delete head_;
170 head_ = NULL; 172 head_ = NULL;
171 return; 173 return;
172 } 174 }
173 } else { 175 } else {
174 Entry *current = head_; 176 Entry *current = head_;
175 do { 177 do {
176 if (current->t == item) { 178 if (current->t == item) {
177 Entry *next = current->next_; 179 Entry *next = current->next_;
178 Entry *prev = current->prev_; 180 Entry *prev = current->prev_;
179 prev->next_ = next; 181 prev->next_ = next;
180 next->prev_ = prev; 182 next->prev_ = prev;
183
184 if (current == head_) {
185 head_ = head_->next_;
186 }
187
181 delete current; 188 delete current;
182 return; 189 return;
183 } 190 }
184 current = current->next_; 191 current = current->next_;
185 } while (current != head_); 192 } while (current != head_);
186 } 193 }
187 } 194 }
188 195
189 void RemoveAll() { 196 void RemoveAll() {
190 while (HasHead()) { 197 while (HasHead()) {
191 RemoveHead(); 198 RemoveHead();
192 } 199 }
193 } 200 }
194 201
195 T head() const { return head_->t; } 202 T head() const { return head_->t; }
196 203
197 bool HasHead() const { 204 bool HasHead() const {
198 return head_ != NULL; 205 return head_ != NULL;
199 } 206 }
200 207
201 void Rotate() { 208 void Rotate() {
202 if (head_ != NULL) { 209 if (head_ != NULL) {
203 ASSERT(head_->next_ != NULL); 210 ASSERT(head_->next_ != NULL);
204 head_ = head_->next_; 211 head_ = head_->next_;
205 } 212 }
206 } 213 }
207 214
208 private: 215 private:
209 struct Entry { 216 struct Entry {
210 explicit Entry(const T& t) : t(t) {} 217 explicit Entry(const T& t) : t(t), next_(NULL), prev_(NULL) {}
211 const T t; 218 const T t;
212 Entry* next_; 219 Entry* next_;
213 Entry* prev_; 220 Entry* prev_;
214 }; 221 };
215 222
216 Entry* head_; 223 Entry* head_;
217 }; 224 };
218 225
219 226
220 class DescriptorInfoBase { 227 class DescriptorInfoBase {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 634
628 private: 635 private:
629 friend class EventHandlerImplementation; 636 friend class EventHandlerImplementation;
630 EventHandlerImplementation delegate_; 637 EventHandlerImplementation delegate_;
631 }; 638 };
632 639
633 } // namespace bin 640 } // namespace bin
634 } // namespace dart 641 } // namespace dart
635 642
636 #endif // BIN_EVENTHANDLER_H_ 643 #endif // BIN_EVENTHANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698