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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 8489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8500 return array; | 8500 return array; |
8501 } | 8501 } |
8502 | 8502 |
8503 | 8503 |
8504 // Compares the contents of two strings by reading and comparing | 8504 // Compares the contents of two strings by reading and comparing |
8505 // int-sized blocks of characters. | 8505 // int-sized blocks of characters. |
8506 template <typename Char> | 8506 template <typename Char> |
8507 static inline bool CompareRawStringContents(const Char* const a, | 8507 static inline bool CompareRawStringContents(const Char* const a, |
8508 const Char* const b, | 8508 const Char* const b, |
8509 int length) { | 8509 int length) { |
8510 int i = 0; | 8510 return CompareChars(a, b, length) == 0; |
8511 #ifndef V8_HOST_CAN_READ_UNALIGNED | |
8512 // If this architecture isn't comfortable reading unaligned ints | |
8513 // then we have to check that the strings are aligned before | |
8514 // comparing them blockwise. | |
8515 const int kAlignmentMask = sizeof(uint32_t) - 1; // NOLINT | |
8516 uintptr_t pa_addr = reinterpret_cast<uintptr_t>(a); | |
8517 uintptr_t pb_addr = reinterpret_cast<uintptr_t>(b); | |
8518 if (((pa_addr & kAlignmentMask) | (pb_addr & kAlignmentMask)) == 0) { | |
8519 #endif | |
8520 const int kStepSize = sizeof(int) / sizeof(Char); // NOLINT | |
8521 int endpoint = length - kStepSize; | |
8522 // Compare blocks until we reach near the end of the string. | |
8523 for (; i <= endpoint; i += kStepSize) { | |
8524 uint32_t wa = *reinterpret_cast<const uint32_t*>(a + i); | |
8525 uint32_t wb = *reinterpret_cast<const uint32_t*>(b + i); | |
8526 if (wa != wb) { | |
8527 return false; | |
8528 } | |
8529 } | |
8530 #ifndef V8_HOST_CAN_READ_UNALIGNED | |
8531 } | |
8532 #endif | |
8533 // Compare the remaining characters that didn't fit into a block. | |
8534 for (; i < length; i++) { | |
8535 if (a[i] != b[i]) { | |
8536 return false; | |
8537 } | |
8538 } | |
8539 return true; | |
8540 } | 8511 } |
8541 | 8512 |
8542 | 8513 |
8543 template<typename Chars1, typename Chars2> | 8514 template<typename Chars1, typename Chars2> |
8544 class RawStringComparator : public AllStatic { | 8515 class RawStringComparator : public AllStatic { |
8545 public: | 8516 public: |
8546 static inline bool compare(const Chars1* a, const Chars2* b, int len) { | 8517 static inline bool compare(const Chars1* a, const Chars2* b, int len) { |
8547 DCHECK(sizeof(Chars1) != sizeof(Chars2)); | 8518 DCHECK(sizeof(Chars1) != sizeof(Chars2)); |
8548 for (int i = 0; i < len; i++) { | 8519 for (int i = 0; i < len; i++) { |
8549 if (a[i] != b[i]) { | 8520 if (a[i] != b[i]) { |
(...skipping 7844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16394 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16365 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16395 static const char* error_messages_[] = { | 16366 static const char* error_messages_[] = { |
16396 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16367 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16397 }; | 16368 }; |
16398 #undef ERROR_MESSAGES_TEXTS | 16369 #undef ERROR_MESSAGES_TEXTS |
16399 return error_messages_[reason]; | 16370 return error_messages_[reason]; |
16400 } | 16371 } |
16401 | 16372 |
16402 | 16373 |
16403 } } // namespace v8::internal | 16374 } } // namespace v8::internal |
OLD | NEW |