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 #ifdef V8_HOST_CAN_READ_UNALIGNED | 9175 |
9176 DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F); | 9176 if (length >= kIntptrSize) { |
9177 const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80; | 9177 // Check unaligned bytes. |
9178 while (chars + sizeof(uintptr_t) <= limit) { | 9178 while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) { |
9179 if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) { | 9179 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
9180 return static_cast<int>(chars - start); | 9180 return static_cast<int>(chars - start); |
| 9181 } |
| 9182 ++chars; |
9181 } | 9183 } |
9182 chars += sizeof(uintptr_t); | 9184 // Check aligned words. |
| 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 } |
9183 } | 9193 } |
9184 #endif | 9194 // Check remaining unaligned bytes. |
9185 while (chars < limit) { | 9195 while (chars < limit) { |
9186 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { | 9196 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) { |
9187 return static_cast<int>(chars - start); | 9197 return static_cast<int>(chars - start); |
9188 } | 9198 } |
9189 ++chars; | 9199 ++chars; |
9190 } | 9200 } |
| 9201 |
9191 return static_cast<int>(chars - start); | 9202 return static_cast<int>(chars - start); |
9192 } | 9203 } |
9193 | 9204 |
9194 static inline bool IsAscii(const char* chars, int length) { | 9205 static inline bool IsAscii(const char* chars, int length) { |
9195 return NonAsciiStart(chars, length) >= length; | 9206 return NonAsciiStart(chars, length) >= length; |
9196 } | 9207 } |
9197 | 9208 |
9198 static inline bool IsAscii(const uint8_t* chars, int length) { | 9209 static inline bool IsAscii(const uint8_t* chars, int length) { |
9199 return | 9210 return |
9200 NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; | 9211 NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length; |
(...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11124 } else { | 11135 } else { |
11125 value &= ~(1 << bit_position); | 11136 value &= ~(1 << bit_position); |
11126 } | 11137 } |
11127 return value; | 11138 return value; |
11128 } | 11139 } |
11129 }; | 11140 }; |
11130 | 11141 |
11131 } } // namespace v8::internal | 11142 } } // namespace v8::internal |
11132 | 11143 |
11133 #endif // V8_OBJECTS_H_ | 11144 #endif // V8_OBJECTS_H_ |
OLD | NEW |