V8 Project
v8::internal::LiteralBuffer Class Reference

#include <scanner.h>

+ Collaboration diagram for v8::internal::LiteralBuffer:

Public Member Functions

 LiteralBuffer ()
 
 ~LiteralBuffer ()
 
 INLINE (void AddChar(uint32_t code_unit))
 
bool is_one_byte () const
 
bool is_contextual_keyword (Vector< const char > keyword) const
 
Vector< const uint16_t > two_byte_literal () const
 
Vector< const uint8_t > one_byte_literal () const
 
int length () const
 
void Reset ()
 
Handle< StringInternalize (Isolate *isolate) const
 

Private Member Functions

int NewCapacity (int min_capacity)
 
void ExpandBuffer ()
 
void ConvertToTwoByte ()
 
 DISALLOW_COPY_AND_ASSIGN (LiteralBuffer)
 

Private Attributes

bool is_one_byte_
 
int position_
 
Vector< bytebacking_store_
 

Static Private Attributes

static const int kInitialCapacity = 16
 
static const int kGrowthFactory = 4
 
static const int kMinConversionSlack = 256
 
static const int kMaxGrowth = 1 * MB
 

Detailed Description

Definition at line 194 of file scanner.h.

Constructor & Destructor Documentation

◆ LiteralBuffer()

v8::internal::LiteralBuffer::LiteralBuffer ( )
inline

Definition at line 196 of file scanner.h.

◆ ~LiteralBuffer()

v8::internal::LiteralBuffer::~LiteralBuffer ( )
inline

Definition at line 198 of file scanner.h.

198  {
199  if (backing_store_.length() > 0) {
201  }
202  }
int length() const
Definition: vector.h:41

References backing_store_, v8::internal::Vector< T >::Dispose(), and v8::internal::Vector< T >::length().

+ Here is the call graph for this function:

Member Function Documentation

◆ ConvertToTwoByte()

void v8::internal::LiteralBuffer::ConvertToTwoByte ( )
inlineprivate

Definition at line 270 of file scanner.h.

270  {
272  Vector<byte> new_store;
273  int new_content_size = position_ * kUC16Size;
274  if (new_content_size >= backing_store_.length()) {
275  // Ensure room for all currently read code units as UC16 as well
276  // as the code unit about to be stored.
277  new_store = Vector<byte>::New(NewCapacity(new_content_size));
278  } else {
279  new_store = backing_store_;
280  }
281  uint8_t* src = backing_store_.start();
282  uint16_t* dst = reinterpret_cast<uint16_t*>(new_store.start());
283  for (int i = position_ - 1; i >= 0; i--) {
284  dst[i] = src[i];
285  }
286  if (new_store.start() != backing_store_.start()) {
288  backing_store_ = new_store;
289  }
290  position_ = new_content_size;
291  is_one_byte_ = false;
292  }
int NewCapacity(int min_capacity)
Definition: scanner.h:257
T * start() const
Definition: vector.h:47
static Vector< T > New(int length)
Definition: vector.h:27
#define DCHECK(condition)
Definition: logging.h:205
unsigned short uint16_t
Definition: unicode.cc:23
const int kUC16Size
Definition: globals.h:187

References backing_store_, DCHECK, v8::internal::Vector< T >::Dispose(), is_one_byte_, v8::internal::kUC16Size, v8::internal::Vector< T >::length(), v8::internal::Vector< T >::New(), NewCapacity(), position_, and v8::internal::Vector< T >::start().

Referenced by INLINE().

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

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::LiteralBuffer::DISALLOW_COPY_AND_ASSIGN ( LiteralBuffer  )
private

◆ ExpandBuffer()

void v8::internal::LiteralBuffer::ExpandBuffer ( )
inlineprivate

Definition at line 263 of file scanner.h.

263  {
264  Vector<byte> new_store = Vector<byte>::New(NewCapacity(kInitialCapacity));
265  MemCopy(new_store.start(), backing_store_.start(), position_);
267  backing_store_ = new_store;
268  }
static const int kInitialCapacity
Definition: scanner.h:253
void MemCopy(void *dest, const void *src, size_t size)
Definition: utils.h:350

References backing_store_, v8::internal::Vector< T >::Dispose(), kInitialCapacity, v8::internal::MemCopy(), v8::internal::Vector< T >::New(), NewCapacity(), position_, and v8::internal::Vector< T >::start().

Referenced by INLINE().

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

◆ INLINE()

v8::internal::LiteralBuffer::INLINE ( void   AddCharuint32_t code_unit)
inline

Definition at line 204 of file scanner.h.

204  {
206  if (is_one_byte_) {
207  if (code_unit <= unibrow::Latin1::kMaxChar) {
208  backing_store_[position_] = static_cast<byte>(code_unit);
210  return;
211  }
213  }
214  DCHECK(code_unit < 0x10000u);
215  *reinterpret_cast<uint16_t*>(&backing_store_[position_]) = code_unit;
216  position_ += kUC16Size;
217  }
static const unsigned kMaxChar
Definition: unicode.h:118
const int kOneByteSize
Definition: globals.h:186

References backing_store_, ConvertToTwoByte(), DCHECK, ExpandBuffer(), is_one_byte_, unibrow::Latin1::kMaxChar, v8::internal::kOneByteSize, v8::internal::kUC16Size, v8::internal::Vector< T >::length(), and position_.

+ Here is the call graph for this function:

◆ Internalize()

Handle< String > v8::internal::LiteralBuffer::Internalize ( Isolate isolate) const

Definition at line 23 of file scanner.cc.

23  {
24  if (is_one_byte()) {
25  return isolate->factory()->InternalizeOneByteString(one_byte_literal());
26  }
27  return isolate->factory()->InternalizeTwoByteString(two_byte_literal());
28 }
Vector< const uint8_t > one_byte_literal() const
Definition: scanner.h:234
Vector< const uint16_t > two_byte_literal() const
Definition: scanner.h:226
bool is_one_byte() const
Definition: scanner.h:219

References v8::internal::Isolate::factory(), is_one_byte(), one_byte_literal(), and two_byte_literal().

Referenced by v8::internal::Parser::HandleSourceURLComments().

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

◆ is_contextual_keyword()

bool v8::internal::LiteralBuffer::is_contextual_keyword ( Vector< const char >  keyword) const
inline

Definition at line 221 of file scanner.h.

221  {
222  return is_one_byte() && keyword.length() == position_ &&
223  (memcmp(keyword.start(), backing_store_.start(), position_) == 0);
224  }

References backing_store_, is_one_byte(), v8::internal::Vector< T >::length(), position_, and v8::internal::Vector< T >::start().

Referenced by v8::internal::Scanner::is_literal_contextual_keyword(), and v8::internal::Scanner::is_next_contextual_keyword().

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

◆ is_one_byte()

bool v8::internal::LiteralBuffer::is_one_byte ( ) const
inline

Definition at line 219 of file scanner.h.

219 { return is_one_byte_; }

References is_one_byte_.

Referenced by Internalize(), is_contextual_keyword(), v8::internal::Scanner::is_literal_one_byte(), v8::internal::Scanner::is_next_literal_one_byte(), and v8::internal::Scanner::ScanIdentifierOrKeyword().

+ Here is the caller graph for this function:

◆ length()

int v8::internal::LiteralBuffer::length ( ) const
inline

Definition at line 241 of file scanner.h.

241  {
242  return is_one_byte_ ? position_ : (position_ >> 1);
243  }

References is_one_byte_, and position_.

Referenced by v8::internal::Parser::HandleSourceURLComments(), v8::internal::Scanner::literal_contains_escapes(), v8::internal::Scanner::literal_length(), and v8::internal::Scanner::next_literal_length().

+ Here is the caller graph for this function:

◆ NewCapacity()

int v8::internal::LiteralBuffer::NewCapacity ( int  min_capacity)
inlineprivate

Definition at line 257 of file scanner.h.

257  {
258  int capacity = Max(min_capacity, backing_store_.length());
259  int new_capacity = Min(capacity * kGrowthFactory, capacity + kMaxGrowth);
260  return new_capacity;
261  }
static const int kMaxGrowth
Definition: scanner.h:256
static const int kGrowthFactory
Definition: scanner.h:254
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)

References backing_store_, kGrowthFactory, kMaxGrowth, v8::internal::Vector< T >::length(), v8::internal::Max(), and v8::internal::Min().

Referenced by ConvertToTwoByte(), and ExpandBuffer().

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

◆ one_byte_literal()

Vector<const uint8_t> v8::internal::LiteralBuffer::one_byte_literal ( ) const
inline

Definition at line 234 of file scanner.h.

234  {
236  return Vector<const uint8_t>(
237  reinterpret_cast<const uint8_t*>(backing_store_.start()),
238  position_);
239  }

References backing_store_, DCHECK, is_one_byte_, position_, and v8::internal::Vector< T >::start().

Referenced by Internalize(), v8::internal::Scanner::literal_one_byte_string(), v8::internal::Scanner::next_literal_one_byte_string(), and v8::internal::Scanner::ScanIdentifierOrKeyword().

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

◆ Reset()

void v8::internal::LiteralBuffer::Reset ( )
inline

Definition at line 245 of file scanner.h.

245  {
246  position_ = 0;
247  is_one_byte_ = true;
248  }

References is_one_byte_, and position_.

Referenced by v8::internal::Scanner::StartLiteral(), and v8::internal::Scanner::TryToParseSourceURLComment().

+ Here is the caller graph for this function:

◆ two_byte_literal()

Vector<const uint16_t> v8::internal::LiteralBuffer::two_byte_literal ( ) const
inline

Definition at line 226 of file scanner.h.

226  {
228  DCHECK((position_ & 0x1) == 0);
229  return Vector<const uint16_t>(
230  reinterpret_cast<const uint16_t*>(backing_store_.start()),
231  position_ >> 1);
232  }

References backing_store_, DCHECK, is_one_byte_, position_, and v8::internal::Vector< T >::start().

Referenced by Internalize(), v8::internal::Scanner::literal_two_byte_string(), and v8::internal::Scanner::next_literal_two_byte_string().

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

Member Data Documentation

◆ backing_store_

Vector<byte> v8::internal::LiteralBuffer::backing_store_
private

◆ is_one_byte_

bool v8::internal::LiteralBuffer::is_one_byte_
private

◆ kGrowthFactory

const int v8::internal::LiteralBuffer::kGrowthFactory = 4
staticprivate

Definition at line 254 of file scanner.h.

Referenced by NewCapacity().

◆ kInitialCapacity

const int v8::internal::LiteralBuffer::kInitialCapacity = 16
staticprivate

Definition at line 253 of file scanner.h.

Referenced by ExpandBuffer().

◆ kMaxGrowth

const int v8::internal::LiteralBuffer::kMaxGrowth = 1 * MB
staticprivate

Definition at line 256 of file scanner.h.

Referenced by NewCapacity().

◆ kMinConversionSlack

const int v8::internal::LiteralBuffer::kMinConversionSlack = 256
staticprivate

Definition at line 255 of file scanner.h.

◆ position_

int v8::internal::LiteralBuffer::position_
private

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