V8 Project
v8::internal::Collector< T, growth_factor, max_growth > Class Template Reference

#include <utils.h>

+ Inheritance diagram for v8::internal::Collector< T, growth_factor, max_growth >:
+ Collaboration diagram for v8::internal::Collector< T, growth_factor, max_growth >:

Public Member Functions

 Collector (int initial_capacity=kMinCapacity)
 
virtual ~Collector ()
 
void Add (T value)
 
Vector< TAddBlock (int size, T initial_value)
 
Vector< TAddBlock (Vector< const T > source)
 
void WriteTo (Vector< T > destination)
 
Vector< TToVector ()
 
virtual void Reset ()
 
int size ()
 

Protected Member Functions

void Grow (int min_capacity)
 
virtual void NewChunk (int new_capacity)
 

Protected Attributes

List< Vector< T > > chunks_
 
Vector< Tcurrent_chunk_
 
int index_
 
int size_
 

Static Protected Attributes

static const int kMinCapacity = 16
 

Detailed Description

template<typename T, int growth_factor = 2, int max_growth = 1 * MB>
class v8::internal::Collector< T, growth_factor, max_growth >

Definition at line 468 of file utils.h.

Constructor & Destructor Documentation

◆ Collector()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
v8::internal::Collector< T, growth_factor, max_growth >::Collector ( int  initial_capacity = kMinCapacity)
inlineexplicit

Definition at line 470 of file utils.h.

471  : index_(0), size_(0) {
472  current_chunk_ = Vector<T>::New(initial_capacity);
473  }
Vector< T > current_chunk_
Definition: utils.h:566
static Vector< T > New(int length)
Definition: vector.h:27

References v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, and v8::internal::Vector< T >::New().

+ Here is the call graph for this function:

◆ ~Collector()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
virtual v8::internal::Collector< T, growth_factor, max_growth >::~Collector ( )
inlinevirtual

Definition at line 475 of file utils.h.

475  {
476  // Free backing store (in reverse allocation order).
477  current_chunk_.Dispose();
478  for (int i = chunks_.length() - 1; i >= 0; i--) {
479  chunks_.at(i).Dispose();
480  }
481  }
List< Vector< T > > chunks_
Definition: utils.h:565

References v8::internal::Collector< T, growth_factor, max_growth >::chunks_, and v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_.

Member Function Documentation

◆ Add()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
void v8::internal::Collector< T, growth_factor, max_growth >::Add ( T  value)
inline

Definition at line 484 of file utils.h.

484  {
485  if (index_ >= current_chunk_.length()) {
486  Grow(1);
487  }
488  current_chunk_[index_] = value;
489  index_++;
490  size_++;
491  }
void Grow(int min_capacity)
Definition: utils.h:571

References v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, v8::internal::Collector< T, growth_factor, max_growth >::Grow(), v8::internal::Collector< T, growth_factor, max_growth >::index_, and v8::internal::Collector< T, growth_factor, max_growth >::size_.

Referenced by v8::internal::DuplicateFinder::BackupKey(), v8::internal::CompleteParserRecorder::LogFunction(), v8::internal::CompleteParserRecorder::LogMessage(), and v8::internal::CompleteParserRecorder::WriteString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddBlock() [1/2]

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
Vector<T> v8::internal::Collector< T, growth_factor, max_growth >::AddBlock ( int  size,
T  initial_value 
)
inline

Definition at line 497 of file utils.h.

497  {
498  DCHECK(size > 0);
499  if (size > current_chunk_.length() - index_) {
500  Grow(size);
501  }
502  T* position = current_chunk_.start() + index_;
503  index_ += size;
504  size_ += size;
505  for (int i = 0; i < size; i++) {
506  position[i] = initial_value;
507  }
508  return Vector<T>(position, size);
509  }
#define DCHECK(condition)
Definition: logging.h:205
#define T(name, string, precedence)
Definition: token.cc:25

References v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, DCHECK, v8::internal::Collector< T, growth_factor, max_growth >::Grow(), v8::internal::Collector< T, growth_factor, max_growth >::index_, v8::internal::Collector< T, growth_factor, max_growth >::size(), v8::internal::Collector< T, growth_factor, max_growth >::size_, and T.

Referenced by v8::internal::DuplicateFinder::BackupKey().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddBlock() [2/2]

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
Vector<T> v8::internal::Collector< T, growth_factor, max_growth >::AddBlock ( Vector< const T source)
inline

Definition at line 516 of file utils.h.

516  {
517  if (source.length() > current_chunk_.length() - index_) {
518  Grow(source.length());
519  }
520  T* position = current_chunk_.start() + index_;
521  index_ += source.length();
522  size_ += source.length();
523  for (int i = 0; i < source.length(); i++) {
524  position[i] = source[i];
525  }
526  return Vector<T>(position, source.length());
527  }
int length() const
Definition: vector.h:41

References v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, v8::internal::Collector< T, growth_factor, max_growth >::Grow(), v8::internal::Collector< T, growth_factor, max_growth >::index_, v8::internal::Vector< T >::length(), v8::internal::Collector< T, growth_factor, max_growth >::size_, and T.

+ Here is the call graph for this function:

◆ Grow()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
void v8::internal::Collector< T, growth_factor, max_growth >::Grow ( int  min_capacity)
inlineprotected

Definition at line 571 of file utils.h.

571  {
572  DCHECK(growth_factor > 1);
573  int new_capacity;
574  int current_length = current_chunk_.length();
575  if (current_length < kMinCapacity) {
576  // The collector started out as empty.
577  new_capacity = min_capacity * growth_factor;
578  if (new_capacity < kMinCapacity) new_capacity = kMinCapacity;
579  } else {
580  int growth = current_length * (growth_factor - 1);
581  if (growth > max_growth) {
582  growth = max_growth;
583  }
584  new_capacity = current_length + growth;
585  if (new_capacity < min_capacity) {
586  new_capacity = min_capacity + growth;
587  }
588  }
589  NewChunk(new_capacity);
590  DCHECK(index_ + min_capacity <= current_chunk_.length());
591  }
static const int kMinCapacity
Definition: utils.h:564
virtual void NewChunk(int new_capacity)
Definition: utils.h:597

References v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, DCHECK, v8::internal::Collector< T, growth_factor, max_growth >::index_, v8::internal::Collector< T, growth_factor, max_growth >::kMinCapacity, and v8::internal::Collector< T, growth_factor, max_growth >::NewChunk().

Referenced by v8::internal::Collector< T, growth_factor, max_growth >::Add(), and v8::internal::Collector< T, growth_factor, max_growth >::AddBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NewChunk()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
virtual void v8::internal::Collector< T, growth_factor, max_growth >::NewChunk ( int  new_capacity)
inlineprotectedvirtual

Reimplemented in v8::internal::SequenceCollector< T, growth_factor, max_growth >, and v8::internal::SequenceCollector< unsigned char >.

Definition at line 597 of file utils.h.

597  {
598  Vector<T> new_chunk = Vector<T>::New(new_capacity);
599  if (index_ > 0) {
600  chunks_.Add(current_chunk_.SubVector(0, index_));
601  } else {
602  current_chunk_.Dispose();
603  }
604  current_chunk_ = new_chunk;
605  index_ = 0;
606  }

References v8::internal::Collector< T, growth_factor, max_growth >::chunks_, v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, v8::internal::Collector< T, growth_factor, max_growth >::index_, and v8::internal::Vector< T >::New().

Referenced by v8::internal::Collector< T, growth_factor, max_growth >::Grow(), and v8::internal::SequenceCollector< T, growth_factor, max_growth >::NewChunk().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Reset()

template<typename T , int growth_factor, int max_growth>
void v8::internal::Collector< T, growth_factor, max_growth >::Reset
virtual

Reimplemented in v8::internal::SequenceCollector< T, growth_factor, max_growth >, and v8::internal::SequenceCollector< unsigned char >.

Definition at line 14 of file utils-inl.h.

14  {
15  for (int i = chunks_.length() - 1; i >= 0; i--) {
16  chunks_.at(i).Dispose();
17  }
18  chunks_.Rewind(0);
19  index_ = 0;
20  size_ = 0;
21 }

Referenced by v8::internal::CompleteParserRecorder::LogMessage(), and v8::internal::SequenceCollector< T, growth_factor, max_growth >::Reset().

+ Here is the caller graph for this function:

◆ size()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
int v8::internal::Collector< T, growth_factor, max_growth >::size ( )
inline

Definition at line 561 of file utils.h.

561 { return size_; }

References v8::internal::Collector< T, growth_factor, max_growth >::size_.

Referenced by v8::internal::Collector< T, growth_factor, max_growth >::AddBlock(), and v8::internal::CompleteParserRecorder::GetScriptData().

+ Here is the caller graph for this function:

◆ ToVector()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
Vector<T> v8::internal::Collector< T, growth_factor, max_growth >::ToVector ( )
inline

Definition at line 551 of file utils.h.

551  {
552  Vector<T> new_store = Vector<T>::New(size_);
553  WriteTo(new_store);
554  return new_store;
555  }
void WriteTo(Vector< T > destination)
Definition: utils.h:531

References v8::internal::Vector< T >::New(), v8::internal::Collector< T, growth_factor, max_growth >::size_, and v8::internal::Collector< T, growth_factor, max_growth >::WriteTo().

Referenced by v8::internal::CompleteParserRecorder::ErrorMessageData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteTo()

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
void v8::internal::Collector< T, growth_factor, max_growth >::WriteTo ( Vector< T destination)
inline

Definition at line 531 of file utils.h.

531  {
532  DCHECK(size_ <= destination.length());
533  int position = 0;
534  for (int i = 0; i < chunks_.length(); i++) {
535  Vector<T> chunk = chunks_.at(i);
536  for (int j = 0; j < chunk.length(); j++) {
537  destination[position] = chunk[j];
538  position++;
539  }
540  }
541  for (int i = 0; i < index_; i++) {
542  destination[position] = current_chunk_[i];
543  position++;
544  }
545  }

References v8::internal::Collector< T, growth_factor, max_growth >::chunks_, v8::internal::Collector< T, growth_factor, max_growth >::current_chunk_, DCHECK, v8::internal::Collector< T, growth_factor, max_growth >::index_, v8::internal::Vector< T >::length(), and v8::internal::Collector< T, growth_factor, max_growth >::size_.

Referenced by v8::internal::CompleteParserRecorder::GetScriptData(), and v8::internal::Collector< T, growth_factor, max_growth >::ToVector().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ chunks_

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
List<Vector<T> > v8::internal::Collector< T, growth_factor, max_growth >::chunks_
protected

◆ current_chunk_

◆ index_

◆ kMinCapacity

template<typename T , int growth_factor = 2, int max_growth = 1 * MB>
const int v8::internal::Collector< T, growth_factor, max_growth >::kMinCapacity = 16
staticprotected

◆ size_


The documentation for this class was generated from the following files: