V8 Project
v8::internal::DuplicateFinder Class Reference

#include <scanner.h>

+ Collaboration diagram for v8::internal::DuplicateFinder:

Public Member Functions

 DuplicateFinder (UnicodeCache *constants)
 
int AddOneByteSymbol (Vector< const uint8_t > key, int value)
 
int AddTwoByteSymbol (Vector< const uint16_t > key, int value)
 
int AddNumber (Vector< const uint8_t > key, int value)
 

Private Member Functions

int AddSymbol (Vector< const uint8_t > key, bool is_one_byte, int value)
 
uint8_t * BackupKey (Vector< const uint8_t > key, bool is_one_byte)
 

Static Private Member Functions

static bool Match (void *first, void *second)
 
static uint32_t Hash (Vector< const uint8_t > key, bool is_one_byte)
 
static bool IsNumberCanonical (Vector< const uint8_t > key)
 

Private Attributes

UnicodeCacheunicode_constants_
 
SequenceCollector< unsigned char > backing_store_
 
HashMap map_
 
char number_buffer_ [kBufferSize]
 

Static Private Attributes

static const int kBufferSize = 100
 

Detailed Description

Definition at line 144 of file scanner.h.

Constructor & Destructor Documentation

◆ DuplicateFinder()

v8::internal::DuplicateFinder::DuplicateFinder ( UnicodeCache constants)
inlineexplicit

Definition at line 146 of file scanner.h.

147  : unicode_constants_(constants),
148  backing_store_(16),
149  map_(&Match) { }
static bool Match(void *first, void *second)
Definition: scanner.cc:1323
UnicodeCache * unicode_constants_
Definition: scanner.h:182
SequenceCollector< unsigned char > backing_store_
Definition: scanner.h:184

Member Function Documentation

◆ AddNumber()

int v8::internal::DuplicateFinder::AddNumber ( Vector< const uint8_t >  key,
int  value 
)

Definition at line 1256 of file scanner.cc.

1256  {
1257  DCHECK(key.length() > 0);
1258  // Quick check for already being in canonical form.
1259  if (IsNumberCanonical(key)) {
1260  return AddOneByteSymbol(key, value);
1261  }
1262 
1264  double double_value = StringToDouble(
1265  unicode_constants_, key, flags, 0.0);
1266  int length;
1267  const char* string;
1268  if (!std::isfinite(double_value)) {
1269  string = "Infinity";
1270  length = 8; // strlen("Infinity");
1271  } else {
1272  string = DoubleToCString(double_value,
1273  Vector<char>(number_buffer_, kBufferSize));
1274  length = StrLength(string);
1275  }
1276  return AddSymbol(Vector<const byte>(reinterpret_cast<const byte*>(string),
1277  length), true, value);
1278 }
int AddOneByteSymbol(Vector< const uint8_t > key, int value)
Definition: scanner.cc:1233
static const int kBufferSize
Definition: scanner.h:180
int AddSymbol(Vector< const uint8_t > key, bool is_one_byte, int value)
Definition: scanner.cc:1243
static bool IsNumberCanonical(Vector< const uint8_t > key)
Definition: scanner.cc:1281
char number_buffer_[kBufferSize]
Definition: scanner.h:187
#define DCHECK(condition)
Definition: logging.h:205
@ ALLOW_IMPLICIT_OCTAL
Definition: conversions.h:104
const char * DoubleToCString(double v, Vector< char > buffer)
Definition: conversions.cc:121
int StrLength(const char *string)
Definition: vector.h:147
double StringToDouble(UnicodeCache *unicode_cache, const char *str, int flags, double empty_string_val)
Definition: conversions.cc:70

References AddOneByteSymbol(), AddSymbol(), v8::internal::ALLOW_BINARY, v8::internal::ALLOW_HEX, v8::internal::ALLOW_IMPLICIT_OCTAL, v8::internal::ALLOW_OCTAL, DCHECK, v8::internal::DoubleToCString(), v8::internal::anonymous_namespace{flags.cc}::flags, IsNumberCanonical(), kBufferSize, v8::internal::Vector< T >::length(), number_buffer_, v8::internal::StringToDouble(), v8::internal::StrLength(), and unicode_constants_.

Referenced by v8::internal::Scanner::FindNumber().

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

◆ AddOneByteSymbol()

int v8::internal::DuplicateFinder::AddOneByteSymbol ( Vector< const uint8_t >  key,
int  value 
)

Definition at line 1233 of file scanner.cc.

1233  {
1234  return AddSymbol(key, true, value);
1235 }

References AddSymbol().

Referenced by AddNumber(), and v8::internal::Scanner::FindSymbol().

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

◆ AddSymbol()

int v8::internal::DuplicateFinder::AddSymbol ( Vector< const uint8_t >  key,
bool  is_one_byte,
int  value 
)
private

Definition at line 1243 of file scanner.cc.

1245  {
1246  uint32_t hash = Hash(key, is_one_byte);
1247  byte* encoding = BackupKey(key, is_one_byte);
1248  HashMap::Entry* entry = map_.Lookup(encoding, hash, true);
1249  int old_value = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1250  entry->value =
1251  reinterpret_cast<void*>(static_cast<intptr_t>(value | old_value));
1252  return old_value;
1253 }
static uint32_t Hash(Vector< const uint8_t > key, bool is_one_byte)
Definition: scanner.cc:1309
uint8_t * BackupKey(Vector< const uint8_t > key, bool is_one_byte)
Definition: scanner.cc:1345
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
Definition: hashmap.h:114

References BackupKey(), Hash(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Lookup(), and map_.

Referenced by AddNumber(), AddOneByteSymbol(), and AddTwoByteSymbol().

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

◆ AddTwoByteSymbol()

int v8::internal::DuplicateFinder::AddTwoByteSymbol ( Vector< const uint16_t >  key,
int  value 
)

Definition at line 1238 of file scanner.cc.

1238  {
1239  return AddSymbol(Vector<const uint8_t>::cast(key), false, value);
1240 }
static Vector< T > cast(Vector< S > input)
Definition: vector.h:98

References AddSymbol().

Referenced by v8::internal::Scanner::FindSymbol().

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

◆ BackupKey()

byte * v8::internal::DuplicateFinder::BackupKey ( Vector< const uint8_t >  key,
bool  is_one_byte 
)
private

Definition at line 1345 of file scanner.cc.

1346  {
1347  uint32_t one_byte_length = (bytes.length() << 1) | (is_one_byte ? 1 : 0);
1349  // Emit one_byte_length as base-128 encoded number, with the 7th bit set
1350  // on the byte of every heptet except the last, least significant, one.
1351  if (one_byte_length >= (1 << 7)) {
1352  if (one_byte_length >= (1 << 14)) {
1353  if (one_byte_length >= (1 << 21)) {
1354  if (one_byte_length >= (1 << 28)) {
1356  static_cast<uint8_t>((one_byte_length >> 28) | 0x80));
1357  }
1359  static_cast<uint8_t>((one_byte_length >> 21) | 0x80u));
1360  }
1362  static_cast<uint8_t>((one_byte_length >> 14) | 0x80u));
1363  }
1364  backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1365  }
1366  backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1367 
1368  backing_store_.AddBlock(bytes);
1369  return backing_store_.EndSequence().start();
1370 }
Vector< T > AddBlock(int size, T initial_value)
Definition: utils.h:497
void Add(T value)
Definition: utils.h:484
Vector< T > EndSequence()
Definition: utils.h:633

References v8::internal::Collector< T, growth_factor, max_growth >::Add(), v8::internal::Collector< T, growth_factor, max_growth >::AddBlock(), backing_store_, v8::internal::SequenceCollector< T, growth_factor, max_growth >::EndSequence(), v8::internal::Vector< T >::length(), and v8::internal::SequenceCollector< T, growth_factor, max_growth >::StartSequence().

Referenced by AddSymbol().

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

◆ Hash()

uint32_t v8::internal::DuplicateFinder::Hash ( Vector< const uint8_t >  key,
bool  is_one_byte 
)
staticprivate

Definition at line 1309 of file scanner.cc.

1309  {
1310  // Primitive hash function, almost identical to the one used
1311  // for strings (except that it's seeded by the length and representation).
1312  int length = key.length();
1313  uint32_t hash = (length << 1) | (is_one_byte ? 1 : 0) ;
1314  for (int i = 0; i < length; i++) {
1315  uint32_t c = key[i];
1316  hash = (hash + c) * 1025;
1317  hash ^= (hash >> 6);
1318  }
1319  return hash;
1320 }

References v8::internal::Vector< T >::length().

Referenced by AddSymbol().

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

◆ IsNumberCanonical()

bool v8::internal::DuplicateFinder::IsNumberCanonical ( Vector< const uint8_t >  key)
staticprivate

Definition at line 1281 of file scanner.cc.

1281  {
1282  // Test for a safe approximation of number literals that are already
1283  // in canonical form: max 15 digits, no leading zeroes, except an
1284  // integer part that is a single zero, and no trailing zeros below
1285  // the decimal point.
1286  int pos = 0;
1287  int length = number.length();
1288  if (number.length() > 15) return false;
1289  if (number[pos] == '0') {
1290  pos++;
1291  } else {
1292  while (pos < length &&
1293  static_cast<unsigned>(number[pos] - '0') <= ('9' - '0')) pos++;
1294  }
1295  if (length == pos) return true;
1296  if (number[pos] != '.') return false;
1297  pos++;
1298  bool invalid_last_digit = true;
1299  while (pos < length) {
1300  uint8_t digit = number[pos] - '0';
1301  if (digit > '9' - '0') return false;
1302  invalid_last_digit = (digit == 0);
1303  pos++;
1304  }
1305  return !invalid_last_digit;
1306 }

References v8::internal::Vector< T >::length().

Referenced by AddNumber().

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

◆ Match()

bool v8::internal::DuplicateFinder::Match ( void *  first,
void *  second 
)
staticprivate

Definition at line 1323 of file scanner.cc.

1323  {
1324  // Decode lengths.
1325  // Length + representation is encoded as base 128, most significant heptet
1326  // first, with a 8th bit being non-zero while there are more heptets.
1327  // The value encodes the number of bytes following, and whether the original
1328  // was Latin1.
1329  byte* s1 = reinterpret_cast<byte*>(first);
1330  byte* s2 = reinterpret_cast<byte*>(second);
1331  uint32_t length_one_byte_field = 0;
1332  byte c1;
1333  do {
1334  c1 = *s1;
1335  if (c1 != *s2) return false;
1336  length_one_byte_field = (length_one_byte_field << 7) | (c1 & 0x7f);
1337  s1++;
1338  s2++;
1339  } while ((c1 & 0x80) != 0);
1340  int length = static_cast<int>(length_one_byte_field >> 1);
1341  return memcmp(s1, s2, length) == 0;
1342 }
const SwVfpRegister s1
const SwVfpRegister s2

References v8::internal::s1, and v8::internal::s2.

Member Data Documentation

◆ backing_store_

SequenceCollector<unsigned char> v8::internal::DuplicateFinder::backing_store_
private

Definition at line 184 of file scanner.h.

Referenced by BackupKey().

◆ kBufferSize

const int v8::internal::DuplicateFinder::kBufferSize = 100
staticprivate

Definition at line 180 of file scanner.h.

Referenced by AddNumber().

◆ map_

HashMap v8::internal::DuplicateFinder::map_
private

Definition at line 185 of file scanner.h.

Referenced by AddSymbol().

◆ number_buffer_

char v8::internal::DuplicateFinder::number_buffer_[kBufferSize]
private

Definition at line 187 of file scanner.h.

Referenced by AddNumber().

◆ unicode_constants_

UnicodeCache* v8::internal::DuplicateFinder::unicode_constants_
private

Definition at line 182 of file scanner.h.

Referenced by AddNumber().


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