OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 9154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9165 int from, | 9165 int from, |
9166 int to); | 9166 int to); |
9167 | 9167 |
9168 // The return value may point to the first aligned word containing the first | 9168 // The return value may point to the first aligned word containing the first |
9169 // non-one-byte character, rather than directly to the non-one-byte character. | 9169 // non-one-byte character, rather than directly to the non-one-byte character. |
9170 // If the return value is >= the passed length, the entire string was | 9170 // If the return value is >= the passed length, the entire string was |
9171 // one-byte. | 9171 // one-byte. |
9172 static inline int NonAsciiStart(const char* chars, int length) { | 9172 static inline int NonAsciiStart(const char* chars, int length) { |
9173 const char* start = chars; | 9173 const char* start = chars; |
9174 const char* limit = chars + length; | 9174 const char* limit = chars + length; |
9175 | 9175 #ifdef V8_HOST_CAN_READ_UNALIGNED |
9176 if (length >= kIntptrSize) { | 9176 DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F); |
9177 // Check unaligned bytes. | 9177 const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
9178 while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) { | 9178 while (chars + sizeof(uintptr_t) <= limit) { |
9179 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { | 9179 if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) { |
9180 return static_cast<int>(chars - start); | 9180 return static_cast<int>(chars - start); |
9181 } | |
9182 ++chars; | |
9183 } | 9181 } |
9184 // Check aligned words. | 9182 chars += sizeof(uintptr_t); |
9185 DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F); | |
9186 const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80; | |
9187 while (chars + sizeof(uintptr_t) <= limit) { | |
9188 if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) { | |
9189 return static_cast<int>(chars - start); | |
9190 } | |
9191 chars += sizeof(uintptr_t); | |
9192 } | |
9193 } | 9183 } |
9194 // Check remaining unaligned bytes. | 9184 #endif |
9195 while (chars < limit) { | 9185 while (chars < limit) { |
9196 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { | 9186 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
9197 return static_cast<int>(chars - start); | 9187 return static_cast<int>(chars - start); |
9198 } | 9188 } |
9199 ++chars; | 9189 ++chars; |
9200 } | 9190 } |
9201 | |
9202 return static_cast<int>(chars - start); | 9191 return static_cast<int>(chars - start); |
9203 } | 9192 } |
9204 | 9193 |
9205 static inline bool IsAscii(const char* chars, int length) { | 9194 static inline bool IsAscii(const char* chars, int length) { |
9206 return NonAsciiStart(chars, length) >= length; | 9195 return NonAsciiStart(chars, length) >= length; |
9207 } | 9196 } |
9208 | 9197 |
9209 static inline bool IsAscii(const uint8_t* chars, int length) { | 9198 static inline bool IsAscii(const uint8_t* chars, int length) { |
9210 return | 9199 return |
9211 NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; | 9200 NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; |
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11135 } else { | 11124 } else { |
11136 value &= ~(1 << bit_position); | 11125 value &= ~(1 << bit_position); |
11137 } | 11126 } |
11138 return value; | 11127 return value; |
11139 } | 11128 } |
11140 }; | 11129 }; |
11141 | 11130 |
11142 } } // namespace v8::internal | 11131 } } // namespace v8::internal |
11143 | 11132 |
11144 #endif // V8_OBJECTS_H_ | 11133 #endif // V8_OBJECTS_H_ |
OLD | NEW |