V8 Project
v8::Utf8LengthHelper Class Reference
+ Inheritance diagram for v8::Utf8LengthHelper:
+ Collaboration diagram for v8::Utf8LengthHelper:

Classes

class  Visitor
 

Public Types

enum  State {
  kEndsWithLeadingSurrogate = 1 << 0 , kStartsWithTrailingSurrogate = 1 << 1 , kLeftmostEdgeIsCalculated = 1 << 2 , kRightmostEdgeIsCalculated = 1 << 3 ,
  kLeftmostEdgeIsSurrogate = 1 << 4 , kRightmostEdgeIsSurrogate = 1 << 5
}
 

Static Public Member Functions

static bool EndsWithSurrogate (uint8_t state)
 
static bool StartsWithSurrogate (uint8_t state)
 
static void MergeLeafLeft (int *length, uint8_t *state, uint8_t leaf_state)
 
static void MergeLeafRight (int *length, uint8_t *state, uint8_t leaf_state)
 
static void MergeTerminal (int *length, uint8_t state, uint8_t *state_out)
 
static int Calculate (i::ConsString *current, uint8_t *state_out)
 
static int Calculate (i::ConsString *current)
 

Static Public Attributes

static const uint8_t kInitialState = 0
 

Private Member Functions

 DISALLOW_IMPLICIT_CONSTRUCTORS (Utf8LengthHelper)
 

Detailed Description

Definition at line 4368 of file api.cc.

Member Enumeration Documentation

◆ State

Enumerator
kEndsWithLeadingSurrogate 
kStartsWithTrailingSurrogate 
kLeftmostEdgeIsCalculated 
kRightmostEdgeIsCalculated 
kLeftmostEdgeIsSurrogate 
kRightmostEdgeIsSurrogate 

Definition at line 4370 of file api.cc.

4370  {
4371  kEndsWithLeadingSurrogate = 1 << 0,
4373  kLeftmostEdgeIsCalculated = 1 << 2,
4374  kRightmostEdgeIsCalculated = 1 << 3,
4375  kLeftmostEdgeIsSurrogate = 1 << 4,
4376  kRightmostEdgeIsSurrogate = 1 << 5
4377  };
@ kLeftmostEdgeIsSurrogate
Definition: api.cc:4375
@ kEndsWithLeadingSurrogate
Definition: api.cc:4371
@ kStartsWithTrailingSurrogate
Definition: api.cc:4372
@ kRightmostEdgeIsSurrogate
Definition: api.cc:4376
@ kRightmostEdgeIsCalculated
Definition: api.cc:4374
@ kLeftmostEdgeIsCalculated
Definition: api.cc:4373

Member Function Documentation

◆ Calculate() [1/2]

static int v8::Utf8LengthHelper::Calculate ( i::ConsString current)
inlinestatic

Definition at line 4539 of file api.cc.

4539  {
4540  uint8_t state = kInitialState;
4541  return Calculate(current, &state);
4542  }
static int Calculate(i::ConsString *current, uint8_t *state_out)
Definition: api.cc:4488
static const uint8_t kInitialState
Definition: api.cc:4379

References Calculate(), and kInitialState.

+ Here is the call graph for this function:

◆ Calculate() [2/2]

static int v8::Utf8LengthHelper::Calculate ( i::ConsString current,
uint8_t *  state_out 
)
inlinestatic

Definition at line 4488 of file api.cc.

4488  {
4489  using namespace internal;
4490  int total_length = 0;
4491  uint8_t state = kInitialState;
4492  while (true) {
4493  i::String* left = current->first();
4494  i::String* right = current->second();
4495  uint8_t right_leaf_state;
4496  uint8_t left_leaf_state;
4497  int leaf_length;
4498  ConsString* left_as_cons =
4499  Visitor::VisitFlat(left, &leaf_length, &left_leaf_state);
4500  if (left_as_cons == NULL) {
4501  total_length += leaf_length;
4502  MergeLeafLeft(&total_length, &state, left_leaf_state);
4503  }
4504  ConsString* right_as_cons =
4505  Visitor::VisitFlat(right, &leaf_length, &right_leaf_state);
4506  if (right_as_cons == NULL) {
4507  total_length += leaf_length;
4508  MergeLeafRight(&total_length, &state, right_leaf_state);
4509  if (left_as_cons != NULL) {
4510  // 1 Leaf node. Descend in place.
4511  current = left_as_cons;
4512  continue;
4513  } else {
4514  // Terminal node.
4515  MergeTerminal(&total_length, state, state_out);
4516  return total_length;
4517  }
4518  } else if (left_as_cons == NULL) {
4519  // 1 Leaf node. Descend in place.
4520  current = right_as_cons;
4521  continue;
4522  }
4523  // Both strings are ConsStrings.
4524  // Recurse on smallest.
4525  if (left->length() < right->length()) {
4526  total_length += Calculate(left_as_cons, &left_leaf_state);
4527  MergeLeafLeft(&total_length, &state, left_leaf_state);
4528  current = right_as_cons;
4529  } else {
4530  total_length += Calculate(right_as_cons, &right_leaf_state);
4531  MergeLeafRight(&total_length, &state, right_leaf_state);
4532  current = left_as_cons;
4533  }
4534  }
4535  UNREACHABLE();
4536  return 0;
4537  }
static i::ConsString * VisitFlat(i::String *string, int *length, uint8_t *state)
Definition: api.cc:4423
static void MergeTerminal(int *length, uint8_t state, uint8_t *state_out)
Definition: api.cc:4475
static void MergeLeafLeft(int *length, uint8_t *state, uint8_t leaf_state)
Definition: api.cc:4439
static void MergeLeafRight(int *length, uint8_t *state, uint8_t leaf_state)
Definition: api.cc:4457
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 UNREACHABLE()
Definition: logging.h:30

References v8::internal::ConsString::first(), kInitialState, v8::internal::String::length(), MergeLeafLeft(), MergeLeafRight(), MergeTerminal(), NULL, v8::internal::ConsString::second(), UNREACHABLE, and v8::Utf8LengthHelper::Visitor::VisitFlat().

Referenced by Calculate(), and v8::Utf8Length().

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

◆ DISALLOW_IMPLICIT_CONSTRUCTORS()

v8::Utf8LengthHelper::DISALLOW_IMPLICIT_CONSTRUCTORS ( Utf8LengthHelper  )
private

◆ EndsWithSurrogate()

static bool v8::Utf8LengthHelper::EndsWithSurrogate ( uint8_t  state)
inlinestatic

Definition at line 4381 of file api.cc.

4381  {
4382  return state & kEndsWithLeadingSurrogate;
4383  }

References kEndsWithLeadingSurrogate.

Referenced by MergeLeafLeft(), MergeLeafRight(), and MergeTerminal().

+ Here is the caller graph for this function:

◆ MergeLeafLeft()

static void v8::Utf8LengthHelper::MergeLeafLeft ( int length,
uint8_t *  state,
uint8_t  leaf_state 
)
inlinestatic

Definition at line 4439 of file api.cc.

4441  {
4442  bool edge_surrogate = StartsWithSurrogate(leaf_state);
4443  if (!(*state & kLeftmostEdgeIsCalculated)) {
4444  DCHECK(!(*state & kLeftmostEdgeIsSurrogate));
4445  *state |= kLeftmostEdgeIsCalculated
4446  | (edge_surrogate ? kLeftmostEdgeIsSurrogate : 0);
4447  } else if (EndsWithSurrogate(*state) && edge_surrogate) {
4449  }
4450  if (EndsWithSurrogate(leaf_state)) {
4451  *state |= kEndsWithLeadingSurrogate;
4452  } else {
4453  *state &= ~kEndsWithLeadingSurrogate;
4454  }
4455  }
static const unsigned kBytesSavedByCombiningSurrogates
Definition: unicode.h:148
static bool StartsWithSurrogate(uint8_t state)
Definition: api.cc:4385
static bool EndsWithSurrogate(uint8_t state)
Definition: api.cc:4381
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, EndsWithSurrogate(), unibrow::Utf8::kBytesSavedByCombiningSurrogates, kEndsWithLeadingSurrogate, kLeftmostEdgeIsCalculated, kLeftmostEdgeIsSurrogate, and StartsWithSurrogate().

Referenced by Calculate().

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

◆ MergeLeafRight()

static void v8::Utf8LengthHelper::MergeLeafRight ( int length,
uint8_t *  state,
uint8_t  leaf_state 
)
inlinestatic

Definition at line 4457 of file api.cc.

4459  {
4460  bool edge_surrogate = EndsWithSurrogate(leaf_state);
4461  if (!(*state & kRightmostEdgeIsCalculated)) {
4462  DCHECK(!(*state & kRightmostEdgeIsSurrogate));
4463  *state |= (kRightmostEdgeIsCalculated
4464  | (edge_surrogate ? kRightmostEdgeIsSurrogate : 0));
4465  } else if (edge_surrogate && StartsWithSurrogate(*state)) {
4467  }
4468  if (StartsWithSurrogate(leaf_state)) {
4469  *state |= kStartsWithTrailingSurrogate;
4470  } else {
4471  *state &= ~kStartsWithTrailingSurrogate;
4472  }
4473  }

References DCHECK, EndsWithSurrogate(), unibrow::Utf8::kBytesSavedByCombiningSurrogates, kRightmostEdgeIsCalculated, kRightmostEdgeIsSurrogate, kStartsWithTrailingSurrogate, and StartsWithSurrogate().

Referenced by Calculate().

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

◆ MergeTerminal()

static void v8::Utf8LengthHelper::MergeTerminal ( int length,
uint8_t  state,
uint8_t *  state_out 
)
inlinestatic

Definition at line 4475 of file api.cc.

4477  {
4478  DCHECK((state & kLeftmostEdgeIsCalculated) &&
4479  (state & kRightmostEdgeIsCalculated));
4480  if (EndsWithSurrogate(state) && StartsWithSurrogate(state)) {
4482  }
4483  *state_out = kInitialState |
4486  }

References DCHECK, EndsWithSurrogate(), unibrow::Utf8::kBytesSavedByCombiningSurrogates, kEndsWithLeadingSurrogate, kInitialState, kLeftmostEdgeIsCalculated, kLeftmostEdgeIsSurrogate, kRightmostEdgeIsCalculated, kRightmostEdgeIsSurrogate, kStartsWithTrailingSurrogate, and StartsWithSurrogate().

Referenced by Calculate().

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

◆ StartsWithSurrogate()

static bool v8::Utf8LengthHelper::StartsWithSurrogate ( uint8_t  state)
inlinestatic

Definition at line 4385 of file api.cc.

4385  {
4386  return state & kStartsWithTrailingSurrogate;
4387  }

References kStartsWithTrailingSurrogate.

Referenced by MergeLeafLeft(), MergeLeafRight(), and MergeTerminal().

+ Here is the caller graph for this function:

Member Data Documentation

◆ kInitialState

const uint8_t v8::Utf8LengthHelper::kInitialState = 0
static

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