OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/allocation-site-scopes.h" | 10 #include "src/allocation-site-scopes.h" |
(...skipping 9097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9108 bool String::IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match) { | 9108 bool String::IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match) { |
9109 int slen = length(); | 9109 int slen = length(); |
9110 // Can't check exact length equality, but we can check bounds. | 9110 // Can't check exact length equality, but we can check bounds. |
9111 int str_len = str.length(); | 9111 int str_len = str.length(); |
9112 if (!allow_prefix_match && | 9112 if (!allow_prefix_match && |
9113 (str_len < slen || | 9113 (str_len < slen || |
9114 str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize))) { | 9114 str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize))) { |
9115 return false; | 9115 return false; |
9116 } | 9116 } |
9117 int i; | 9117 int i; |
9118 unsigned remaining_in_str = static_cast<unsigned>(str_len); | 9118 size_t remaining_in_str = static_cast<size_t>(str_len); |
9119 const uint8_t* utf8_data = reinterpret_cast<const uint8_t*>(str.start()); | 9119 const uint8_t* utf8_data = reinterpret_cast<const uint8_t*>(str.start()); |
9120 for (i = 0; i < slen && remaining_in_str > 0; i++) { | 9120 for (i = 0; i < slen && remaining_in_str > 0; i++) { |
9121 unsigned cursor = 0; | 9121 size_t cursor = 0; |
9122 uint32_t r = unibrow::Utf8::ValueOf(utf8_data, remaining_in_str, &cursor); | 9122 uint32_t r = unibrow::Utf8::ValueOf(utf8_data, remaining_in_str, &cursor); |
9123 DCHECK(cursor > 0 && cursor <= remaining_in_str); | 9123 DCHECK(cursor > 0 && cursor <= remaining_in_str); |
9124 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { | 9124 if (r > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
9125 if (i > slen - 1) return false; | 9125 if (i > slen - 1) return false; |
9126 if (Get(i++) != unibrow::Utf16::LeadSurrogate(r)) return false; | 9126 if (Get(i++) != unibrow::Utf16::LeadSurrogate(r)) return false; |
9127 if (Get(i) != unibrow::Utf16::TrailSurrogate(r)) return false; | 9127 if (Get(i) != unibrow::Utf16::TrailSurrogate(r)) return false; |
9128 } else { | 9128 } else { |
9129 if (Get(i) != r) return false; | 9129 if (Get(i) != r) return false; |
9130 } | 9130 } |
9131 utf8_data += cursor; | 9131 utf8_data += cursor; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9285 if (vector_length <= 1) { | 9285 if (vector_length <= 1) { |
9286 DCHECK(vector_length == 0 || | 9286 DCHECK(vector_length == 0 || |
9287 static_cast<uint8_t>(chars.start()[0]) <= | 9287 static_cast<uint8_t>(chars.start()[0]) <= |
9288 unibrow::Utf8::kMaxOneByteChar); | 9288 unibrow::Utf8::kMaxOneByteChar); |
9289 *utf16_length_out = vector_length; | 9289 *utf16_length_out = vector_length; |
9290 return HashSequentialString(chars.start(), vector_length, seed); | 9290 return HashSequentialString(chars.start(), vector_length, seed); |
9291 } | 9291 } |
9292 // Start with a fake length which won't affect computation. | 9292 // Start with a fake length which won't affect computation. |
9293 // It will be updated later. | 9293 // It will be updated later. |
9294 StringHasher hasher(String::kMaxArrayIndexSize, seed); | 9294 StringHasher hasher(String::kMaxArrayIndexSize, seed); |
9295 unsigned remaining = static_cast<unsigned>(vector_length); | 9295 size_t remaining = static_cast<size_t>(vector_length); |
9296 const uint8_t* stream = reinterpret_cast<const uint8_t*>(chars.start()); | 9296 const uint8_t* stream = reinterpret_cast<const uint8_t*>(chars.start()); |
9297 int utf16_length = 0; | 9297 int utf16_length = 0; |
9298 bool is_index = true; | 9298 bool is_index = true; |
9299 DCHECK(hasher.is_array_index_); | 9299 DCHECK(hasher.is_array_index_); |
9300 while (remaining > 0) { | 9300 while (remaining > 0) { |
9301 unsigned consumed = 0; | 9301 size_t consumed = 0; |
9302 uint32_t c = unibrow::Utf8::ValueOf(stream, remaining, &consumed); | 9302 uint32_t c = unibrow::Utf8::ValueOf(stream, remaining, &consumed); |
9303 DCHECK(consumed > 0 && consumed <= remaining); | 9303 DCHECK(consumed > 0 && consumed <= remaining); |
9304 stream += consumed; | 9304 stream += consumed; |
9305 remaining -= consumed; | 9305 remaining -= consumed; |
9306 bool is_two_characters = c > unibrow::Utf16::kMaxNonSurrogateCharCode; | 9306 bool is_two_characters = c > unibrow::Utf16::kMaxNonSurrogateCharCode; |
9307 utf16_length += is_two_characters ? 2 : 1; | 9307 utf16_length += is_two_characters ? 2 : 1; |
9308 // No need to keep hashing. But we do need to calculate utf16_length. | 9308 // No need to keep hashing. But we do need to calculate utf16_length. |
9309 if (utf16_length > String::kMaxHashCalcLength) continue; | 9309 if (utf16_length > String::kMaxHashCalcLength) continue; |
9310 if (is_two_characters) { | 9310 if (is_two_characters) { |
9311 uint16_t c1 = unibrow::Utf16::LeadSurrogate(c); | 9311 uint16_t c1 = unibrow::Utf16::LeadSurrogate(c); |
(...skipping 7554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16866 Handle<DependentCode> codes = | 16866 Handle<DependentCode> codes = |
16867 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), | 16867 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), |
16868 DependentCode::kPropertyCellChangedGroup, | 16868 DependentCode::kPropertyCellChangedGroup, |
16869 info->object_wrapper()); | 16869 info->object_wrapper()); |
16870 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); | 16870 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); |
16871 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( | 16871 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( |
16872 cell, info->zone()); | 16872 cell, info->zone()); |
16873 } | 16873 } |
16874 | 16874 |
16875 } } // namespace v8::internal | 16875 } } // namespace v8::internal |
OLD | NEW |