OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 } else { | 607 } else { |
608 int growth = current_length * (growth_factor - 1); | 608 int growth = current_length * (growth_factor - 1); |
609 if (growth > max_growth) { | 609 if (growth > max_growth) { |
610 growth = max_growth; | 610 growth = max_growth; |
611 } | 611 } |
612 new_capacity = current_length + growth; | 612 new_capacity = current_length + growth; |
613 if (new_capacity < min_capacity) { | 613 if (new_capacity < min_capacity) { |
614 new_capacity = min_capacity + growth; | 614 new_capacity = min_capacity + growth; |
615 } | 615 } |
616 } | 616 } |
617 Vector<T> new_chunk = Vector<T>::New(new_capacity); | 617 Vector<T> new_chunk = Vector<T>::New(new_capacity); |
Rico
2011/09/08 13:42:37
We don't need this new_chunk vector anymore right?
Lasse Reichstein
2011/09/08 13:43:43
Gone.
| |
618 int new_index = PrepareGrow(new_chunk); | 618 NewChunk(new_capacity); |
619 if (index_ > 0) { | |
620 chunks_.Add(current_chunk_.SubVector(0, index_)); | |
621 } else { | |
622 // Can happen if the call to PrepareGrow moves everything into | |
623 // the new chunk. | |
624 current_chunk_.Dispose(); | |
625 } | |
626 current_chunk_ = new_chunk; | |
627 index_ = new_index; | |
628 ASSERT(index_ + min_capacity <= current_chunk_.length()); | 619 ASSERT(index_ + min_capacity <= current_chunk_.length()); |
629 } | 620 } |
630 | 621 |
631 // Before replacing the current chunk, give a subclass the option to move | 622 // Before replacing the current chunk, give a subclass the option to move |
632 // some of the current data into the new chunk. The function may update | 623 // some of the current data into the new chunk. The function may update |
633 // the current index_ value to represent data no longer in the current chunk. | 624 // the current index_ value to represent data no longer in the current chunk. |
634 // Returns the initial index of the new chunk (after copied data). | 625 // Returns the initial index of the new chunk (after copied data). |
635 virtual int PrepareGrow(Vector<T> new_chunk) { | 626 virtual void NewChunk(int new_capacity) { |
636 return 0; | 627 Vector<T> new_chunk = Vector<T>::New(new_capacity); |
628 if (index_ > 0) { | |
629 chunks_.Add(current_chunk_.SubVector(0, index_)); | |
630 } else { | |
631 current_chunk_.Dispose(); | |
632 } | |
633 current_chunk_ = new_chunk; | |
634 index_ = 0; | |
637 } | 635 } |
638 }; | 636 }; |
639 | 637 |
640 | 638 |
641 /* | 639 /* |
642 * A collector that allows sequences of values to be guaranteed to | 640 * A collector that allows sequences of values to be guaranteed to |
643 * stay consecutive. | 641 * stay consecutive. |
644 * If the backing store grows while a sequence is active, the current | 642 * If the backing store grows while a sequence is active, the current |
645 * sequence might be moved, but after the sequence is ended, it will | 643 * sequence might be moved, but after the sequence is ended, it will |
646 * not move again. | 644 * not move again. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 virtual void Reset() { | 679 virtual void Reset() { |
682 sequence_start_ = kNoSequence; | 680 sequence_start_ = kNoSequence; |
683 this->Collector<T, growth_factor, max_growth>::Reset(); | 681 this->Collector<T, growth_factor, max_growth>::Reset(); |
684 } | 682 } |
685 | 683 |
686 private: | 684 private: |
687 static const int kNoSequence = -1; | 685 static const int kNoSequence = -1; |
688 int sequence_start_; | 686 int sequence_start_; |
689 | 687 |
690 // Move the currently active sequence to the new chunk. | 688 // Move the currently active sequence to the new chunk. |
691 virtual int PrepareGrow(Vector<T> new_chunk) { | 689 virtual void NewChunk(int new_capacity) { |
692 if (sequence_start_ != kNoSequence) { | 690 if (sequence_start_ == kNoSequence) { |
693 int sequence_length = this->index_ - sequence_start_; | 691 // Fall back on default behavior if no sequence has been started. |
694 // The new chunk is always larger than the current chunk, so there | 692 this->Collector<T, growth_factor, max_growth>::NewChunk(new_capacity); |
695 // is room for the copy. | 693 return; |
696 ASSERT(sequence_length < new_chunk.length()); | |
697 for (int i = 0; i < sequence_length; i++) { | |
698 new_chunk[i] = this->current_chunk_[sequence_start_ + i]; | |
699 } | |
700 this->index_ = sequence_start_; | |
701 sequence_start_ = 0; | |
702 return sequence_length; | |
703 } | 694 } |
704 return 0; | 695 int sequence_length = this->index_ - sequence_start_; |
696 Vector<T> new_chunk = Vector<T>::New(sequence_length + new_capacity); | |
697 ASSERT(sequence_length < new_chunk.length()); | |
698 for (int i = 0; i < sequence_length; i++) { | |
699 new_chunk[i] = this->current_chunk_[sequence_start_ + i]; | |
700 } | |
701 if (sequence_start_ > 0) { | |
702 this->chunks_.Add(this->current_chunk_.SubVector(0, sequence_start_)); | |
703 } else { | |
704 this->current_chunk_.Dispose(); | |
705 } | |
706 this->current_chunk_ = new_chunk; | |
707 this->index_ = sequence_length; | |
708 sequence_start_ = 0; | |
705 } | 709 } |
706 }; | 710 }; |
707 | 711 |
708 | 712 |
709 // Compare ASCII/16bit chars to ASCII/16bit chars. | 713 // Compare ASCII/16bit chars to ASCII/16bit chars. |
710 template <typename lchar, typename rchar> | 714 template <typename lchar, typename rchar> |
711 static inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { | 715 static inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { |
712 const lchar* limit = lhs + chars; | 716 const lchar* limit = lhs + chars; |
713 #ifdef V8_HOST_CAN_READ_UNALIGNED | 717 #ifdef V8_HOST_CAN_READ_UNALIGNED |
714 if (sizeof(*lhs) == sizeof(*rhs)) { | 718 if (sizeof(*lhs) == sizeof(*rhs)) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
911 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); | 915 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
912 return 1 << element; | 916 return 1 << element; |
913 } | 917 } |
914 | 918 |
915 T bits_; | 919 T bits_; |
916 }; | 920 }; |
917 | 921 |
918 } } // namespace v8::internal | 922 } } // namespace v8::internal |
919 | 923 |
920 #endif // V8_UTILS_H_ | 924 #endif // V8_UTILS_H_ |
OLD | NEW |