| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { } | 516 explicit ScopedVector(int length) : Vector<T>(NewArray<T>(length), length) { } |
| 517 ~ScopedVector() { | 517 ~ScopedVector() { |
| 518 DeleteArray(this->start()); | 518 DeleteArray(this->start()); |
| 519 } | 519 } |
| 520 | 520 |
| 521 private: | 521 private: |
| 522 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedVector); | 522 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedVector); |
| 523 }; | 523 }; |
| 524 | 524 |
| 525 #define STATIC_ASCII_VECTOR(x) \ | 525 #define STATIC_ASCII_VECTOR(x) \ |
| 526 v8::internal::Vector<const char>(x, ARRAY_SIZE(x)-1) | 526 v8::internal::Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(x), \ |
| 527 ARRAY_SIZE(x)-1) |
| 527 | 528 |
| 528 inline Vector<const char> CStrVector(const char* data) { | 529 inline Vector<const char> CStrVector(const char* data) { |
| 529 return Vector<const char>(data, StrLength(data)); | 530 return Vector<const char>(data, StrLength(data)); |
| 530 } | 531 } |
| 531 | 532 |
| 533 inline Vector<const uint8_t> OneByteVector(const char* data, int length) { |
| 534 return Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), length); |
| 535 } |
| 536 |
| 537 inline Vector<const uint8_t> OneByteVector(const char* data) { |
| 538 return OneByteVector(data, StrLength(data)); |
| 539 } |
| 540 |
| 532 inline Vector<char> MutableCStrVector(char* data) { | 541 inline Vector<char> MutableCStrVector(char* data) { |
| 533 return Vector<char>(data, StrLength(data)); | 542 return Vector<char>(data, StrLength(data)); |
| 534 } | 543 } |
| 535 | 544 |
| 536 inline Vector<char> MutableCStrVector(char* data, int max) { | 545 inline Vector<char> MutableCStrVector(char* data, int max) { |
| 537 int length = StrLength(data); | 546 int length = StrLength(data); |
| 538 return Vector<char>(data, (length < max) ? length : max); | 547 return Vector<char>(data, (length < max) ? length : max); |
| 539 } | 548 } |
| 540 | 549 |
| 541 | 550 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 } | 769 } |
| 761 this->current_chunk_ = new_chunk; | 770 this->current_chunk_ = new_chunk; |
| 762 this->index_ = sequence_length; | 771 this->index_ = sequence_length; |
| 763 sequence_start_ = 0; | 772 sequence_start_ = 0; |
| 764 } | 773 } |
| 765 }; | 774 }; |
| 766 | 775 |
| 767 | 776 |
| 768 // Compare ASCII/16bit chars to ASCII/16bit chars. | 777 // Compare ASCII/16bit chars to ASCII/16bit chars. |
| 769 template <typename lchar, typename rchar> | 778 template <typename lchar, typename rchar> |
| 770 inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { | 779 inline int CompareCharsUnsigned(const lchar* lhs, |
| 780 const rchar* rhs, |
| 781 int chars) { |
| 771 const lchar* limit = lhs + chars; | 782 const lchar* limit = lhs + chars; |
| 772 #ifdef V8_HOST_CAN_READ_UNALIGNED | 783 #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 773 if (sizeof(*lhs) == sizeof(*rhs)) { | 784 if (sizeof(*lhs) == sizeof(*rhs)) { |
| 774 // Number of characters in a uintptr_t. | 785 // Number of characters in a uintptr_t. |
| 775 static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT | 786 static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT |
| 776 while (lhs <= limit - kStepSize) { | 787 while (lhs <= limit - kStepSize) { |
| 777 if (*reinterpret_cast<const uintptr_t*>(lhs) != | 788 if (*reinterpret_cast<const uintptr_t*>(lhs) != |
| 778 *reinterpret_cast<const uintptr_t*>(rhs)) { | 789 *reinterpret_cast<const uintptr_t*>(rhs)) { |
| 779 break; | 790 break; |
| 780 } | 791 } |
| 781 lhs += kStepSize; | 792 lhs += kStepSize; |
| 782 rhs += kStepSize; | 793 rhs += kStepSize; |
| 783 } | 794 } |
| 784 } | 795 } |
| 785 #endif | 796 #endif |
| 786 while (lhs < limit) { | 797 while (lhs < limit) { |
| 787 int r = static_cast<int>(*lhs) - static_cast<int>(*rhs); | 798 int r = static_cast<int>(*lhs) - static_cast<int>(*rhs); |
| 788 if (r != 0) return r; | 799 if (r != 0) return r; |
| 789 ++lhs; | 800 ++lhs; |
| 790 ++rhs; | 801 ++rhs; |
| 791 } | 802 } |
| 792 return 0; | 803 return 0; |
| 793 } | 804 } |
| 794 | 805 |
| 806 template<typename lchar, typename rchar> |
| 807 inline int CompareChars(const lchar* lhs, const rchar* rhs, int chars) { |
| 808 ASSERT(sizeof(lchar) <= 2); |
| 809 ASSERT(sizeof(rchar) <= 2); |
| 810 if (sizeof(lchar) == 1) { |
| 811 if (sizeof(rchar) == 1) { |
| 812 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(lhs), |
| 813 reinterpret_cast<const uint8_t*>(rhs), |
| 814 chars); |
| 815 } else { |
| 816 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(lhs), |
| 817 reinterpret_cast<const uint16_t*>(rhs), |
| 818 chars); |
| 819 } |
| 820 } else { |
| 821 if (sizeof(rchar) == 1) { |
| 822 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(lhs), |
| 823 reinterpret_cast<const uint8_t*>(rhs), |
| 824 chars); |
| 825 } else { |
| 826 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(lhs), |
| 827 reinterpret_cast<const uint16_t*>(rhs), |
| 828 chars); |
| 829 } |
| 830 } |
| 831 } |
| 832 |
| 795 | 833 |
| 796 // Calculate 10^exponent. | 834 // Calculate 10^exponent. |
| 797 inline int TenToThe(int exponent) { | 835 inline int TenToThe(int exponent) { |
| 798 ASSERT(exponent <= 9); | 836 ASSERT(exponent <= 9); |
| 799 ASSERT(exponent >= 1); | 837 ASSERT(exponent >= 1); |
| 800 int answer = 10; | 838 int answer = 10; |
| 801 for (int i = 1; i < exponent; i++) answer *= 10; | 839 for (int i = 1; i < exponent; i++) answer *= 10; |
| 802 return answer; | 840 return answer; |
| 803 } | 841 } |
| 804 | 842 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 | 1076 |
| 1039 // Every compiled stub starts with this id. | 1077 // Every compiled stub starts with this id. |
| 1040 static const int kStubEntryId = 5; | 1078 static const int kStubEntryId = 5; |
| 1041 | 1079 |
| 1042 int id_; | 1080 int id_; |
| 1043 }; | 1081 }; |
| 1044 | 1082 |
| 1045 } } // namespace v8::internal | 1083 } } // namespace v8::internal |
| 1046 | 1084 |
| 1047 #endif // V8_UTILS_H_ | 1085 #endif // V8_UTILS_H_ |
| OLD | NEW |