|
29 | 29 |
|
30 | 30 | #include "src/api.h"
|
31 | 31 | #include "src/objects.h"
|
| 32 | +#include "src/utils.h" |
32 | 33 |
|
33 | 34 | namespace v8 {
|
34 | 35 | namespace internal {
|
@@ -379,11 +380,32 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
|
379 | 380 | bool AstValueFactory::AstRawStringCompare(void* a, void* b) {
|
380 | 381 | const AstRawString* lhs = static_cast<AstRawString*>(a);
|
381 | 382 | const AstRawString* rhs = static_cast<AstRawString*>(b);
|
382 |
| - if (lhs->is_one_byte() != rhs->is_one_byte()) return false; |
| 383 | + if (lhs->length() != rhs->length()) return false; |
383 | 384 | if (lhs->hash() != rhs->hash()) return false;
|
384 |
| - int len = lhs->byte_length(); |
385 |
| - if (rhs->byte_length() != len) return false; |
386 |
| - return memcmp(lhs->raw_data(), rhs->raw_data(), len) == 0; |
| 385 | + const unsigned char* l = lhs->raw_data(); |
| 386 | + const unsigned char* r = rhs->raw_data(); |
| 387 | + size_t length = rhs->length(); |
| 388 | + if (lhs->is_one_byte()) { |
| 389 | + if (rhs->is_one_byte()) { |
| 390 | + return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l), |
| 391 | + reinterpret_cast<const uint8_t*>(r), |
| 392 | + length) == 0; |
| 393 | + } else { |
| 394 | + return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l), |
| 395 | + reinterpret_cast<const uint16_t*>(r), |
| 396 | + length) == 0; |
| 397 | + } |
| 398 | + } else { |
| 399 | + if (rhs->is_one_byte()) { |
| 400 | + return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
| 401 | + reinterpret_cast<const uint8_t*>(r), |
| 402 | + length) == 0; |
| 403 | + } else { |
| 404 | + return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
| 405 | + reinterpret_cast<const uint16_t*>(r), |
| 406 | + length) == 0; |
| 407 | + } |
| 408 | + } |
387 | 409 | }
|
388 | 410 | } // namespace internal
|
389 | 411 | } // namespace v8
|
0 commit comments