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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 position++; | 553 position++; |
554 } | 554 } |
555 } | 555 } |
556 for (int i = 0; i < index_; i++) { | 556 for (int i = 0; i < index_; i++) { |
557 new_store[position] = current_chunk_[i]; | 557 new_store[position] = current_chunk_[i]; |
558 position++; | 558 position++; |
559 } | 559 } |
560 return Vector<T>(new_store, total_length); | 560 return Vector<T>(new_store, total_length); |
561 } | 561 } |
562 | 562 |
| 563 // Resets the collector to be empty. |
| 564 virtual void Reset() { |
| 565 for (int i = chunks_.length() - 1; i >= 0; i--) { |
| 566 chunks_.at(i).Dispose(); |
| 567 } |
| 568 chunks_.Rewind(0); |
| 569 index_ = 0; |
| 570 } |
| 571 |
563 protected: | 572 protected: |
564 static const int kMinCapacity = 16; | 573 static const int kMinCapacity = 16; |
565 List<Vector<T> > chunks_; | 574 List<Vector<T> > chunks_; |
566 T* current_chunk_; | 575 T* current_chunk_; |
567 int growth_factor_; | 576 int growth_factor_; |
568 int max_growth_; | 577 int max_growth_; |
569 int current_capacity_; | 578 int current_capacity_; |
570 int index_; | 579 int index_; |
571 | 580 |
572 // Creates a new current chunk, and stores the old chunk in the chunks_ list. | 581 // Creates a new current chunk, and stores the old chunk in the chunks_ list. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 } | 634 } |
626 | 635 |
627 Vector<T> EndSequence() { | 636 Vector<T> EndSequence() { |
628 ASSERT(sequence_start_ != kNoSequence); | 637 ASSERT(sequence_start_ != kNoSequence); |
629 int sequence_start = sequence_start_; | 638 int sequence_start = sequence_start_; |
630 sequence_start_ = kNoSequence; | 639 sequence_start_ = kNoSequence; |
631 return Vector<T>(this->current_chunk_ + sequence_start, | 640 return Vector<T>(this->current_chunk_ + sequence_start, |
632 this->index_ - sequence_start); | 641 this->index_ - sequence_start); |
633 } | 642 } |
634 | 643 |
| 644 // Drops the currently added sequence, and all collected elements in it. |
| 645 void DropSequence() { |
| 646 ASSERT(sequence_start_ != kNoSequence); |
| 647 this->index_ = sequence_start_; |
| 648 sequence_start_ = kNoSequence; |
| 649 } |
| 650 |
| 651 virtual void Reset() { |
| 652 sequence_start_ = kNoSequence; |
| 653 this->Collector<T>::Reset(); |
| 654 } |
| 655 |
635 private: | 656 private: |
636 static const int kNoSequence = -1; | 657 static const int kNoSequence = -1; |
637 int sequence_start_; | 658 int sequence_start_; |
638 | 659 |
639 // Move the currently active sequence to the new chunk. | 660 // Move the currently active sequence to the new chunk. |
640 virtual int PrepareGrow(Vector<T> new_chunk) { | 661 virtual int PrepareGrow(Vector<T> new_chunk) { |
641 if (sequence_start_ != kNoSequence) { | 662 if (sequence_start_ != kNoSequence) { |
642 int sequence_length = this->index_ - sequence_start_; | 663 int sequence_length = this->index_ - sequence_start_; |
643 // The new chunk is always larger than the current chunk, so there | 664 // The new chunk is always larger than the current chunk, so there |
644 // is room for the copy. | 665 // is room for the copy. |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 } | 940 } |
920 | 941 |
921 template <class Dest, class Source> | 942 template <class Dest, class Source> |
922 inline Dest BitCast(Source* source) { | 943 inline Dest BitCast(Source* source) { |
923 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source)); | 944 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source)); |
924 } | 945 } |
925 | 946 |
926 } } // namespace v8::internal | 947 } } // namespace v8::internal |
927 | 948 |
928 #endif // V8_UTILS_H_ | 949 #endif // V8_UTILS_H_ |
OLD | NEW |