OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 // elements to the vector, and return it. | 633 // elements to the vector, and return it. |
634 // The caller is responsible for freeing the memory of the returned | 634 // The caller is responsible for freeing the memory of the returned |
635 // vector (e.g., using Vector::Dispose). | 635 // vector (e.g., using Vector::Dispose). |
636 Vector<T> ToVector() { | 636 Vector<T> ToVector() { |
637 Vector<T> new_store = Vector<T>::New(size_); | 637 Vector<T> new_store = Vector<T>::New(size_); |
638 WriteTo(new_store); | 638 WriteTo(new_store); |
639 return new_store; | 639 return new_store; |
640 } | 640 } |
641 | 641 |
642 // Resets the collector to be empty. | 642 // Resets the collector to be empty. |
643 virtual void Reset(); | 643 virtual void Reset() { |
| 644 for (int i = chunks_.length() - 1; i >= 0; i--) { |
| 645 chunks_.at(i).Dispose(); |
| 646 } |
| 647 chunks_.Rewind(0); |
| 648 index_ = 0; |
| 649 size_ = 0; |
| 650 } |
644 | 651 |
645 // Total number of elements added to collector so far. | 652 // Total number of elements added to collector so far. |
646 inline int size() { return size_; } | 653 inline int size() { return size_; } |
647 | 654 |
648 protected: | 655 protected: |
649 static const int kMinCapacity = 16; | 656 static const int kMinCapacity = 16; |
650 List<Vector<T> > chunks_; | 657 List<Vector<T> > chunks_; |
651 Vector<T> current_chunk_; // Block of memory currently being written into. | 658 Vector<T> current_chunk_; // Block of memory currently being written into. |
652 int index_; // Current index in current chunk. | 659 int index_; // Current index in current chunk. |
653 int size_; // Total number of elements in collector. | 660 int size_; // Total number of elements in collector. |
(...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 // Takes the address of the limit variable in order to find out where | 1702 // Takes the address of the limit variable in order to find out where |
1696 // the top of stack is right now. | 1703 // the top of stack is right now. |
1697 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); | 1704 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); |
1698 return limit; | 1705 return limit; |
1699 } | 1706 } |
1700 | 1707 |
1701 } // namespace internal | 1708 } // namespace internal |
1702 } // namespace v8 | 1709 } // namespace v8 |
1703 | 1710 |
1704 #endif // V8_UTILS_H_ | 1711 #endif // V8_UTILS_H_ |
OLD | NEW |