OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7277 return true; | 7277 return true; |
7278 } else if (map == heap->ascii_string_map()) { | 7278 } else if (map == heap->ascii_string_map()) { |
7279 this->set_map(heap->undetectable_ascii_string_map()); | 7279 this->set_map(heap->undetectable_ascii_string_map()); |
7280 return true; | 7280 return true; |
7281 } | 7281 } |
7282 // Rest cannot be marked as undetectable | 7282 // Rest cannot be marked as undetectable |
7283 return false; | 7283 return false; |
7284 } | 7284 } |
7285 | 7285 |
7286 | 7286 |
7287 bool String::IsEqualTo(Vector<const char> str) { | 7287 bool String::IsUtf8EqualTo(Vector<const char> str) { |
7288 int slen = length(); | 7288 int slen = length(); |
7289 // Can't check exact length equality, but we can check bounds. | 7289 // Can't check exact length equality, but we can check bounds. |
7290 int str_len = str.length(); | 7290 int str_len = str.length(); |
7291 if (str_len < slen || | 7291 if (str_len < slen || |
7292 str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize)) { | 7292 str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize)) { |
7293 return false; | 7293 return false; |
7294 } | 7294 } |
7295 int i; | 7295 int i; |
7296 unsigned remaining_in_str = static_cast<unsigned>(str_len); | 7296 unsigned remaining_in_str = static_cast<unsigned>(str_len); |
7297 const uint8_t* utf8_data = reinterpret_cast<const uint8_t*>(str.start()); | 7297 const uint8_t* utf8_data = reinterpret_cast<const uint8_t*>(str.start()); |
7298 for (i = 0; i < slen && remaining_in_str > 0; i++) { | 7298 for (i = 0; i < slen && remaining_in_str > 0; i++) { |
7299 unsigned cursor = 0; | 7299 unsigned cursor = 0; |
7300 uint32_t r = unibrow::Utf8::ValueOf(utf8_data, remaining_in_str, &cursor); | 7300 uint32_t r = unibrow::Utf8::ValueOf(utf8_data, remaining_in_str, &cursor); |
7301 ASSERT(cursor > 0 && cursor <= remaining_in_str); | 7301 ASSERT(cursor > 0 && cursor <= remaining_in_str); |
7302 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { | 7302 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
7303 if (i > slen - 1) return false; | 7303 if (i > slen - 1) return false; |
7304 if (Get(i++) != unibrow::Utf16::LeadSurrogate(r)) return false; | 7304 if (Get(i++) != unibrow::Utf16::LeadSurrogate(r)) return false; |
7305 if (Get(i) != unibrow::Utf16::TrailSurrogate(r)) return false; | 7305 if (Get(i) != unibrow::Utf16::TrailSurrogate(r)) return false; |
7306 } else { | 7306 } else { |
7307 if (Get(i) != r) return false; | 7307 if (Get(i) != r) return false; |
7308 } | 7308 } |
7309 utf8_data += cursor; | 7309 utf8_data += cursor; |
7310 remaining_in_str -= cursor; | 7310 remaining_in_str -= cursor; |
7311 } | 7311 } |
7312 return i == slen && remaining_in_str == 0; | 7312 return i == slen && remaining_in_str == 0; |
7313 } | 7313 } |
7314 | 7314 |
7315 | 7315 |
7316 bool String::IsAsciiEqualTo(Vector<const char> str) { | 7316 bool String::IsOneByteEqualTo(Vector<const uint8_t> str) { |
7317 int slen = length(); | 7317 int slen = length(); |
7318 if (str.length() != slen) return false; | 7318 if (str.length() != slen) return false; |
7319 FlatContent content = GetFlatContent(); | 7319 FlatContent content = GetFlatContent(); |
7320 if (content.IsAscii()) { | 7320 if (content.IsAscii()) { |
7321 return CompareChars(content.ToAsciiVector().start(), | 7321 return CompareChars(content.ToOneByteVector().start(), |
7322 str.start(), slen) == 0; | 7322 str.start(), slen) == 0; |
7323 } | 7323 } |
7324 for (int i = 0; i < slen; i++) { | 7324 for (int i = 0; i < slen; i++) { |
7325 if (Get(i) != static_cast<uint16_t>(str[i])) return false; | 7325 if (Get(i) != static_cast<uint16_t>(str[i])) return false; |
7326 } | 7326 } |
7327 return true; | 7327 return true; |
7328 } | 7328 } |
7329 | 7329 |
7330 | 7330 |
7331 bool String::IsTwoByteEqualTo(Vector<const uc16> str) { | 7331 bool String::IsTwoByteEqualTo(Vector<const uc16> str) { |
(...skipping 4048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11380 Smi* flags_; | 11380 Smi* flags_; |
11381 }; | 11381 }; |
11382 | 11382 |
11383 // Utf8SymbolKey carries a vector of chars as key. | 11383 // Utf8SymbolKey carries a vector of chars as key. |
11384 class Utf8SymbolKey : public HashTableKey { | 11384 class Utf8SymbolKey : public HashTableKey { |
11385 public: | 11385 public: |
11386 explicit Utf8SymbolKey(Vector<const char> string, uint32_t seed) | 11386 explicit Utf8SymbolKey(Vector<const char> string, uint32_t seed) |
11387 : string_(string), hash_field_(0), seed_(seed) { } | 11387 : string_(string), hash_field_(0), seed_(seed) { } |
11388 | 11388 |
11389 bool IsMatch(Object* string) { | 11389 bool IsMatch(Object* string) { |
11390 return String::cast(string)->IsEqualTo(string_); | 11390 return String::cast(string)->IsUtf8EqualTo(string_); |
11391 } | 11391 } |
11392 | 11392 |
11393 uint32_t Hash() { | 11393 uint32_t Hash() { |
11394 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | 11394 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
11395 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | 11395 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
11396 uint32_t result = hash_field_ >> String::kHashShift; | 11396 uint32_t result = hash_field_ >> String::kHashShift; |
11397 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 11397 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
11398 return result; | 11398 return result; |
11399 } | 11399 } |
11400 | 11400 |
11401 uint32_t HashForObject(Object* other) { | 11401 uint32_t HashForObject(Object* other) { |
11402 return String::cast(other)->Hash(); | 11402 return String::cast(other)->Hash(); |
11403 } | 11403 } |
11404 | 11404 |
11405 MaybeObject* AsObject() { | 11405 MaybeObject* AsObject() { |
11406 if (hash_field_ == 0) Hash(); | 11406 if (hash_field_ == 0) Hash(); |
11407 return Isolate::Current()->heap()->AllocateSymbol( | 11407 return Isolate::Current()->heap()->AllocateSymbolFromUtf8( |
11408 string_, chars_, hash_field_); | 11408 string_, chars_, hash_field_); |
11409 } | 11409 } |
11410 | 11410 |
11411 Vector<const char> string_; | 11411 Vector<const char> string_; |
11412 uint32_t hash_field_; | 11412 uint32_t hash_field_; |
11413 int chars_; // Caches the number of characters when computing the hash code. | 11413 int chars_; // Caches the number of characters when computing the hash code. |
11414 uint32_t seed_; | 11414 uint32_t seed_; |
11415 }; | 11415 }; |
11416 | 11416 |
11417 | 11417 |
(...skipping 18 matching lines...) Expand all Loading... |
11436 return String::cast(other)->Hash(); | 11436 return String::cast(other)->Hash(); |
11437 } | 11437 } |
11438 | 11438 |
11439 Vector<const Char> string_; | 11439 Vector<const Char> string_; |
11440 uint32_t hash_field_; | 11440 uint32_t hash_field_; |
11441 uint32_t seed_; | 11441 uint32_t seed_; |
11442 }; | 11442 }; |
11443 | 11443 |
11444 | 11444 |
11445 | 11445 |
11446 class AsciiSymbolKey : public SequentialSymbolKey<char> { | 11446 class OneByteSymbolKey : public SequentialSymbolKey<uint8_t> { |
11447 public: | 11447 public: |
11448 AsciiSymbolKey(Vector<const char> str, uint32_t seed) | 11448 OneByteSymbolKey(Vector<const uint8_t> str, uint32_t seed) |
11449 : SequentialSymbolKey<char>(str, seed) { } | 11449 : SequentialSymbolKey<uint8_t>(str, seed) { } |
11450 | 11450 |
11451 bool IsMatch(Object* string) { | 11451 bool IsMatch(Object* string) { |
11452 return String::cast(string)->IsAsciiEqualTo(string_); | 11452 return String::cast(string)->IsOneByteEqualTo(string_); |
11453 } | 11453 } |
11454 | 11454 |
11455 MaybeObject* AsObject() { | 11455 MaybeObject* AsObject() { |
11456 if (hash_field_ == 0) Hash(); | 11456 if (hash_field_ == 0) Hash(); |
11457 return HEAP->AllocateAsciiSymbol(string_, hash_field_); | 11457 return HEAP->AllocateOneByteSymbol(string_, hash_field_); |
11458 } | 11458 } |
11459 }; | 11459 }; |
11460 | 11460 |
11461 | 11461 |
11462 class SubStringAsciiSymbolKey : public HashTableKey { | 11462 class SubStringOneByteSymbolKey : public HashTableKey { |
11463 public: | 11463 public: |
11464 explicit SubStringAsciiSymbolKey(Handle<SeqOneByteString> string, | 11464 explicit SubStringOneByteSymbolKey(Handle<SeqOneByteString> string, |
11465 int from, | 11465 int from, |
11466 int length) | 11466 int length) |
11467 : string_(string), from_(from), length_(length) { } | 11467 : string_(string), from_(from), length_(length) { } |
11468 | 11468 |
11469 uint32_t Hash() { | 11469 uint32_t Hash() { |
11470 ASSERT(length_ >= 0); | 11470 ASSERT(length_ >= 0); |
11471 ASSERT(from_ + length_ <= string_->length()); | 11471 ASSERT(from_ + length_ <= string_->length()); |
11472 char* chars = string_->GetChars() + from_; | 11472 char* chars = string_->GetChars() + from_; |
11473 hash_field_ = StringHasher::HashSequentialString( | 11473 hash_field_ = StringHasher::HashSequentialString( |
11474 chars, length_, string_->GetHeap()->HashSeed()); | 11474 chars, length_, string_->GetHeap()->HashSeed()); |
11475 uint32_t result = hash_field_ >> String::kHashShift; | 11475 uint32_t result = hash_field_ >> String::kHashShift; |
11476 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 11476 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
11477 return result; | 11477 return result; |
11478 } | 11478 } |
11479 | 11479 |
11480 | 11480 |
11481 uint32_t HashForObject(Object* other) { | 11481 uint32_t HashForObject(Object* other) { |
11482 return String::cast(other)->Hash(); | 11482 return String::cast(other)->Hash(); |
11483 } | 11483 } |
11484 | 11484 |
11485 bool IsMatch(Object* string) { | 11485 bool IsMatch(Object* string) { |
11486 Vector<const char> chars(string_->GetChars() + from_, length_); | 11486 Vector<const uint8_t> chars(string_->GetCharsU() + from_, length_); |
11487 return String::cast(string)->IsAsciiEqualTo(chars); | 11487 return String::cast(string)->IsOneByteEqualTo(chars); |
11488 } | 11488 } |
11489 | 11489 |
11490 MaybeObject* AsObject() { | 11490 MaybeObject* AsObject() { |
11491 if (hash_field_ == 0) Hash(); | 11491 if (hash_field_ == 0) Hash(); |
11492 Vector<const char> chars(string_->GetChars() + from_, length_); | 11492 Vector<const uint8_t> chars( |
11493 return HEAP->AllocateAsciiSymbol(chars, hash_field_); | 11493 reinterpret_cast<uint8_t*>(string_->GetChars()) + from_, |
| 11494 length_); |
| 11495 return HEAP->AllocateOneByteSymbol(chars, hash_field_); |
11494 } | 11496 } |
11495 | 11497 |
11496 private: | 11498 private: |
11497 Handle<SeqOneByteString> string_; | 11499 Handle<SeqOneByteString> string_; |
11498 int from_; | 11500 int from_; |
11499 int length_; | 11501 int length_; |
11500 uint32_t hash_field_; | 11502 uint32_t hash_field_; |
11501 }; | 11503 }; |
11502 | 11504 |
11503 | 11505 |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12403 } | 12405 } |
12404 | 12406 |
12405 | 12407 |
12406 MaybeObject* SymbolTable::LookupUtf8Symbol(Vector<const char> str, | 12408 MaybeObject* SymbolTable::LookupUtf8Symbol(Vector<const char> str, |
12407 Object** s) { | 12409 Object** s) { |
12408 Utf8SymbolKey key(str, GetHeap()->HashSeed()); | 12410 Utf8SymbolKey key(str, GetHeap()->HashSeed()); |
12409 return LookupKey(&key, s); | 12411 return LookupKey(&key, s); |
12410 } | 12412 } |
12411 | 12413 |
12412 | 12414 |
12413 MaybeObject* SymbolTable::LookupOneByteSymbol(Vector<const char> str, | 12415 MaybeObject* SymbolTable::LookupOneByteSymbol(Vector<const uint8_t> str, |
12414 Object** s) { | 12416 Object** s) { |
12415 AsciiSymbolKey key(str, GetHeap()->HashSeed()); | 12417 OneByteSymbolKey key(str, GetHeap()->HashSeed()); |
12416 return LookupKey(&key, s); | 12418 return LookupKey(&key, s); |
12417 } | 12419 } |
12418 | 12420 |
12419 | 12421 |
12420 MaybeObject* SymbolTable::LookupSubStringOneByteSymbol( | 12422 MaybeObject* SymbolTable::LookupSubStringOneByteSymbol( |
12421 Handle<SeqOneByteString> str, | 12423 Handle<SeqOneByteString> str, |
12422 int from, | 12424 int from, |
12423 int length, | 12425 int length, |
12424 Object** s) { | 12426 Object** s) { |
12425 SubStringAsciiSymbolKey key(str, from, length); | 12427 SubStringOneByteSymbolKey key(str, from, length); |
12426 return LookupKey(&key, s); | 12428 return LookupKey(&key, s); |
12427 } | 12429 } |
12428 | 12430 |
12429 | 12431 |
12430 MaybeObject* SymbolTable::LookupTwoByteSymbol(Vector<const uc16> str, | 12432 MaybeObject* SymbolTable::LookupTwoByteSymbol(Vector<const uc16> str, |
12431 Object** s) { | 12433 Object** s) { |
12432 TwoByteSymbolKey key(str, GetHeap()->HashSeed()); | 12434 TwoByteSymbolKey key(str, GetHeap()->HashSeed()); |
12433 return LookupKey(&key, s); | 12435 return LookupKey(&key, s); |
12434 } | 12436 } |
12435 | 12437 |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13723 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13725 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13724 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13726 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13725 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13727 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13726 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13728 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13727 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13729 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13728 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13730 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13729 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13731 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13730 } | 13732 } |
13731 | 13733 |
13732 } } // namespace v8::internal | 13734 } } // namespace v8::internal |
OLD | NEW |