OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 269 } |
270 // Assemble. | 270 // Assemble. |
271 left->right_ = current->left_; | 271 left->right_ = current->left_; |
272 right->left_ = current->right_; | 272 right->left_ = current->right_; |
273 current->left_ = dummy->right_; | 273 current->left_ = dummy->right_; |
274 current->right_ = dummy->left_; | 274 current->right_ = dummy->left_; |
275 root_ = current; | 275 root_ = current; |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 template <typename Node, class Callback> | 279 template <typename Config> template <class Callback> |
280 static void DoForEach(Node* node, Callback* callback) { | 280 void ZoneSplayTree<Config>::ForEach(Callback* callback) { |
281 if (node == NULL) return; | 281 // Pre-allocate some space for tiny trees. |
282 DoForEach<Node, Callback>(node->left(), callback); | 282 ZoneList<Node*> nodes_to_visit(10); |
283 callback->Call(node->key(), node->value()); | 283 nodes_to_visit.Add(root_); |
284 DoForEach<Node, Callback>(node->right(), callback); | 284 int pos = 0; |
| 285 while (pos < nodes_to_visit.length()) { |
| 286 Node* node = nodes_to_visit[pos++]; |
| 287 if (node == NULL) continue; |
| 288 callback->Call(node->key(), node->value()); |
| 289 nodes_to_visit.Add(node->left()); |
| 290 nodes_to_visit.Add(node->right()); |
| 291 } |
285 } | 292 } |
286 | 293 |
287 | 294 |
288 } } // namespace v8::internal | 295 } } // namespace v8::internal |
289 | 296 |
290 #endif // V8_ZONE_INL_H_ | 297 #endif // V8_ZONE_INL_H_ |
OLD | NEW |