V8 Project
v8::internal::ConsStringIteratorOp Class Reference

#include <objects.h>

+ Collaboration diagram for v8::internal::ConsStringIteratorOp:

Public Member Functions

 ConsStringIteratorOp ()
 
 ConsStringIteratorOp (ConsString *cons_string, int offset=0)
 
void Reset (ConsString *cons_string, int offset=0)
 
StringNext (int *offset_out)
 

Private Member Functions

 STATIC_ASSERT (IS_POWER_OF_TWO(kStackSize))
 
void PushLeft (ConsString *string)
 
void PushRight (ConsString *string)
 
void AdjustMaximumDepth ()
 
void Pop ()
 
bool StackBlown ()
 
void Initialize (ConsString *cons_string, int offset)
 
StringContinue (int *offset_out)
 
StringNextLeaf (bool *blew_stack)
 
StringSearch (int *offset_out)
 
 DISALLOW_COPY_AND_ASSIGN (ConsStringIteratorOp)
 

Static Private Member Functions

static int OffsetForDepth (int depth)
 

Private Attributes

ConsStringframes_ [kStackSize]
 
ConsStringroot_
 
int depth_
 
int maximum_depth_
 
int consumed_
 

Static Private Attributes

static const int kStackSize = 32
 
static const int kDepthMask = kStackSize-1
 

Detailed Description

Definition at line 9286 of file objects.h.

Constructor & Destructor Documentation

◆ ConsStringIteratorOp() [1/2]

v8::internal::ConsStringIteratorOp::ConsStringIteratorOp ( )
inline

Definition at line 9288 of file objects.h.

9288 {}

◆ ConsStringIteratorOp() [2/2]

v8::internal::ConsStringIteratorOp::ConsStringIteratorOp ( ConsString cons_string,
int  offset = 0 
)
inlineexplicit

Definition at line 9289 of file objects.h.

9290  {
9291  Reset(cons_string, offset);
9292  }
void Reset(ConsString *cons_string, int offset=0)
Definition: objects.h:9293

Member Function Documentation

◆ AdjustMaximumDepth()

void v8::internal::ConsStringIteratorOp::AdjustMaximumDepth ( )
inlineprivate

Definition at line 3664 of file objects-inl.h.

Referenced by NextLeaf(), and Search().

+ Here is the caller graph for this function:

◆ Continue()

String * v8::internal::ConsStringIteratorOp::Continue ( int offset_out)
private

Definition at line 8206 of file objects.cc.

8206  {
8207  DCHECK(depth_ != 0);
8208  DCHECK_EQ(0, *offset_out);
8209  bool blew_stack = StackBlown();
8210  String* string = NULL;
8211  // Get the next leaf if there is one.
8212  if (!blew_stack) string = NextLeaf(&blew_stack);
8213  // Restart search from root.
8214  if (blew_stack) {
8215  DCHECK(string == NULL);
8216  string = Search(offset_out);
8217  }
8218  // Ensure future calls return null immediately.
8219  if (string == NULL) Reset(NULL);
8220  return string;
8221 }
String * NextLeaf(bool *blew_stack)
Definition: objects.cc:8285
String * Search(int *offset_out)
Definition: objects.cc:8224
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206

References DCHECK, DCHECK_EQ, depth_, NextLeaf(), NULL, Reset(), Search(), and StackBlown().

+ Here is the call graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::ConsStringIteratorOp::DISALLOW_COPY_AND_ASSIGN ( ConsStringIteratorOp  )
private

◆ Initialize()

void v8::internal::ConsStringIteratorOp::Initialize ( ConsString cons_string,
int  offset 
)
private

Definition at line 8195 of file objects.cc.

8195  {
8196  DCHECK(cons_string != NULL);
8197  root_ = cons_string;
8198  consumed_ = offset;
8199  // Force stack blown condition to trigger restart.
8200  depth_ = 1;
8202  DCHECK(StackBlown());
8203 }

References consumed_, DCHECK, depth_, kStackSize, maximum_depth_, NULL, root_, and StackBlown().

+ Here is the call graph for this function:

◆ Next()

String* v8::internal::ConsStringIteratorOp::Next ( int offset_out)
inline

Definition at line 9300 of file objects.h.

9300  {
9301  *offset_out = 0;
9302  if (depth_ == 0) return NULL;
9303  return Continue(offset_out);
9304  }
String * Continue(int *offset_out)
Definition: objects.cc:8206

References NULL.

Referenced by v8::internal::StringComparator::State::Advance(), v8::internal::IteratingStringHasher::Hash(), v8::internal::StringCharacterStream::HasMore(), v8::internal::StringComparator::State::Init(), and v8::internal::StringCharacterStream::Reset().

+ Here is the caller graph for this function:

◆ NextLeaf()

String * v8::internal::ConsStringIteratorOp::NextLeaf ( bool blew_stack)
private

Definition at line 8285 of file objects.cc.

8285  {
8286  while (true) {
8287  // Tree traversal complete.
8288  if (depth_ == 0) {
8289  *blew_stack = false;
8290  return NULL;
8291  }
8292  // We've lost track of higher nodes.
8293  if (StackBlown()) {
8294  *blew_stack = true;
8295  return NULL;
8296  }
8297  // Go right.
8298  ConsString* cons_string = frames_[OffsetForDepth(depth_ - 1)];
8299  String* string = cons_string->second();
8300  int32_t type = string->map()->instance_type();
8301  if ((type & kStringRepresentationMask) != kConsStringTag) {
8302  // Pop stack so next iteration is in correct place.
8303  Pop();
8304  int length = string->length();
8305  // Could be a flattened ConsString.
8306  if (length == 0) continue;
8307  consumed_ += length;
8308  return string;
8309  }
8310  cons_string = ConsString::cast(string);
8311  PushRight(cons_string);
8312  // Need to traverse all the way left.
8313  while (true) {
8314  // Continue left.
8315  string = cons_string->first();
8316  type = string->map()->instance_type();
8317  if ((type & kStringRepresentationMask) != kConsStringTag) {
8319  int length = string->length();
8320  DCHECK(length != 0);
8321  consumed_ += length;
8322  return string;
8323  }
8324  cons_string = ConsString::cast(string);
8325  PushLeft(cons_string);
8326  }
8327  }
8328  UNREACHABLE();
8329  return NULL;
8330 }
void PushRight(ConsString *string)
Definition: objects-inl.h:3658
static int OffsetForDepth(int depth)
Definition: objects-inl.h:3648
ConsString * frames_[kStackSize]
Definition: objects.h:9325
void PushLeft(ConsString *string)
Definition: objects-inl.h:3653
#define UNREACHABLE()
Definition: logging.h:30
int int32_t
Definition: unicode.cc:24
@ kConsStringTag
Definition: objects.h:564
const uint32_t kStringRepresentationMask
Definition: objects.h:561

References AdjustMaximumDepth(), consumed_, DCHECK, depth_, v8::internal::ConsString::first(), frames_, v8::internal::Map::instance_type(), v8::internal::kConsStringTag, v8::internal::kStringRepresentationMask, v8::internal::HeapObject::map(), NULL, OffsetForDepth(), Pop(), PushLeft(), PushRight(), v8::internal::ConsString::second(), StackBlown(), and UNREACHABLE.

Referenced by Continue().

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

◆ OffsetForDepth()

int v8::internal::ConsStringIteratorOp::OffsetForDepth ( int  depth)
inlinestaticprivate

Definition at line 3648 of file objects-inl.h.

3648  {
3649  return depth & kDepthMask;
3650 }

Referenced by NextLeaf().

+ Here is the caller graph for this function:

◆ Pop()

void v8::internal::ConsStringIteratorOp::Pop ( )
inlineprivate

Definition at line 3669 of file objects-inl.h.

3669  {
3670  DCHECK(depth_ > 0);
3672  depth_--;
3673 }

References DCHECK.

Referenced by NextLeaf(), and Search().

+ Here is the caller graph for this function:

◆ PushLeft()

void v8::internal::ConsStringIteratorOp::PushLeft ( ConsString string)
inlineprivate

Definition at line 3653 of file objects-inl.h.

3653  {
3654  frames_[depth_++ & kDepthMask] = string;
3655 }

Referenced by NextLeaf(), and Search().

+ Here is the caller graph for this function:

◆ PushRight()

void v8::internal::ConsStringIteratorOp::PushRight ( ConsString string)
inlineprivate

Definition at line 3658 of file objects-inl.h.

3658  {
3659  // Inplace update.
3660  frames_[(depth_-1) & kDepthMask] = string;
3661 }

Referenced by NextLeaf(), and Search().

+ Here is the caller graph for this function:

◆ Reset()

void v8::internal::ConsStringIteratorOp::Reset ( ConsString cons_string,
int  offset = 0 
)
inline

Definition at line 9293 of file objects.h.

9293  {
9294  depth_ = 0;
9295  // Next will always return NULL.
9296  if (cons_string == NULL) return;
9297  Initialize(cons_string, offset);
9298  }
void Initialize(ConsString *cons_string, int offset)
Definition: objects.cc:8195

References NULL.

Referenced by Continue(), v8::internal::StringComparator::State::Init(), v8::internal::StringCharacterStream::Reset(), and Search().

+ Here is the caller graph for this function:

◆ Search()

String * v8::internal::ConsStringIteratorOp::Search ( int offset_out)
private

Definition at line 8224 of file objects.cc.

8224  {
8225  ConsString* cons_string = root_;
8226  // Reset the stack, pushing the root string.
8227  depth_ = 1;
8228  maximum_depth_ = 1;
8229  frames_[0] = cons_string;
8230  const int consumed = consumed_;
8231  int offset = 0;
8232  while (true) {
8233  // Loop until the string is found which contains the target offset.
8234  String* string = cons_string->first();
8235  int length = string->length();
8236  int32_t type;
8237  if (consumed < offset + length) {
8238  // Target offset is in the left branch.
8239  // Keep going if we're still in a ConString.
8240  type = string->map()->instance_type();
8241  if ((type & kStringRepresentationMask) == kConsStringTag) {
8242  cons_string = ConsString::cast(string);
8243  PushLeft(cons_string);
8244  continue;
8245  }
8246  // Tell the stack we're done descending.
8248  } else {
8249  // Descend right.
8250  // Update progress through the string.
8251  offset += length;
8252  // Keep going if we're still in a ConString.
8253  string = cons_string->second();
8254  type = string->map()->instance_type();
8255  if ((type & kStringRepresentationMask) == kConsStringTag) {
8256  cons_string = ConsString::cast(string);
8257  PushRight(cons_string);
8258  continue;
8259  }
8260  // Need this to be updated for the current string.
8261  length = string->length();
8262  // Account for the possibility of an empty right leaf.
8263  // This happens only if we have asked for an offset outside the string.
8264  if (length == 0) {
8265  // Reset so future operations will return null immediately.
8266  Reset(NULL);
8267  return NULL;
8268  }
8269  // Tell the stack we're done descending.
8271  // Pop stack so next iteration is in correct place.
8272  Pop();
8273  }
8274  DCHECK(length != 0);
8275  // Adjust return values and exit.
8276  consumed_ = offset + length;
8277  *offset_out = consumed - offset;
8278  return string;
8279  }
8280  UNREACHABLE();
8281  return NULL;
8282 }

References AdjustMaximumDepth(), consumed_, DCHECK, depth_, v8::internal::ConsString::first(), frames_, v8::internal::Map::instance_type(), v8::internal::kConsStringTag, v8::internal::kStringRepresentationMask, v8::internal::String::length(), v8::internal::HeapObject::map(), maximum_depth_, NULL, Pop(), PushLeft(), PushRight(), Reset(), root_, v8::internal::ConsString::second(), and UNREACHABLE.

Referenced by Continue().

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

◆ StackBlown()

bool v8::internal::ConsStringIteratorOp::StackBlown ( )
inlineprivate

Definition at line 9317 of file objects.h.

9317 { return maximum_depth_ - depth_ == kStackSize; }

Referenced by Continue(), Initialize(), and NextLeaf().

+ Here is the caller graph for this function:

◆ STATIC_ASSERT()

v8::internal::ConsStringIteratorOp::STATIC_ASSERT ( IS_POWER_OF_TWO(kStackSize )
private

Member Data Documentation

◆ consumed_

int v8::internal::ConsStringIteratorOp::consumed_
private

Definition at line 9329 of file objects.h.

Referenced by Initialize(), NextLeaf(), and Search().

◆ depth_

int v8::internal::ConsStringIteratorOp::depth_
private

Definition at line 9327 of file objects.h.

Referenced by Continue(), Initialize(), NextLeaf(), and Search().

◆ frames_

ConsString* v8::internal::ConsStringIteratorOp::frames_[kStackSize]
private

Definition at line 9325 of file objects.h.

Referenced by NextLeaf(), and Search().

◆ kDepthMask

const int v8::internal::ConsStringIteratorOp::kDepthMask = kStackSize-1
staticprivate

Definition at line 9309 of file objects.h.

◆ kStackSize

const int v8::internal::ConsStringIteratorOp::kStackSize = 32
staticprivate

Definition at line 9307 of file objects.h.

Referenced by Initialize().

◆ maximum_depth_

int v8::internal::ConsStringIteratorOp::maximum_depth_
private

Definition at line 9328 of file objects.h.

Referenced by Initialize(), and Search().

◆ root_

ConsString* v8::internal::ConsStringIteratorOp::root_
private

Definition at line 9326 of file objects.h.

Referenced by Initialize(), and Search().


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