Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: src/utils.h

Issue 559913002: Rename ascii to one-byte where applicable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/jsregexp.cc ('K') | « src/uri.js ('k') | src/vector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_UTILS_H_ 5 #ifndef V8_UTILS_H_
6 #define V8_UTILS_H_ 6 #define V8_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 } else { 667 } else {
668 this->current_chunk_.Dispose(); 668 this->current_chunk_.Dispose();
669 } 669 }
670 this->current_chunk_ = new_chunk; 670 this->current_chunk_ = new_chunk;
671 this->index_ = sequence_length; 671 this->index_ = sequence_length;
672 sequence_start_ = 0; 672 sequence_start_ = 0;
673 } 673 }
674 }; 674 };
675 675
676 676
677 // Compare ASCII/16bit chars to ASCII/16bit chars. 677 // Compare 8bit/16bit chars to 8bit/16bit chars.
678 template <typename lchar, typename rchar> 678 template <typename lchar, typename rchar>
679 inline int CompareCharsUnsigned(const lchar* lhs, 679 inline int CompareCharsUnsigned(const lchar* lhs,
680 const rchar* rhs, 680 const rchar* rhs,
681 int chars) { 681 int chars) {
682 const lchar* limit = lhs + chars; 682 const lchar* limit = lhs + chars;
683 #ifdef V8_HOST_CAN_READ_UNALIGNED 683 #ifdef V8_HOST_CAN_READ_UNALIGNED
684 if (sizeof(*lhs) == sizeof(*rhs)) { 684 if (sizeof(*lhs) == sizeof(*rhs)) {
685 // Number of characters in a uintptr_t. 685 // Number of characters in a uintptr_t.
686 static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT 686 static const int kStepSize = sizeof(uintptr_t) / sizeof(*lhs); // NOLINT
687 while (lhs <= limit - kStepSize) { 687 while (lhs <= limit - kStepSize) {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 #else 1221 #else
1222 for (int i = 0; i < counter; i++) { 1222 for (int i = 0; i < counter; i++) {
1223 dest[i] = value; 1223 dest[i] = value;
1224 } 1224 }
1225 #endif 1225 #endif
1226 1226
1227 #undef STOS 1227 #undef STOS
1228 } 1228 }
1229 1229
1230 1230
1231 // Simple wrapper that allows an ExternalString to refer to a
1232 // Vector<const char>. Doesn't assume ownership of the data.
1233 class AsciiStringAdapter: public v8::String::ExternalAsciiStringResource {
1234 public:
1235 explicit AsciiStringAdapter(Vector<const char> data) : data_(data) {}
1236
1237 virtual const char* data() const { return data_.start(); }
1238
1239 virtual size_t length() const { return data_.length(); }
1240
1241 private:
1242 Vector<const char> data_;
1243 };
1244
1245
1246 // Simple support to read a file into a 0-terminated C-string. 1231 // Simple support to read a file into a 0-terminated C-string.
1247 // The returned buffer must be freed by the caller. 1232 // The returned buffer must be freed by the caller.
1248 // On return, *exits tells whether the file existed. 1233 // On return, *exits tells whether the file existed.
1249 Vector<const char> ReadFile(const char* filename, 1234 Vector<const char> ReadFile(const char* filename,
1250 bool* exists, 1235 bool* exists,
1251 bool verbose = true); 1236 bool verbose = true);
1252 Vector<const char> ReadFile(FILE* file, 1237 Vector<const char> ReadFile(FILE* file,
1253 bool* exists, 1238 bool* exists,
1254 bool verbose = true); 1239 bool verbose = true);
1255 1240
1256 1241
1257 template <typename sourcechar, typename sinkchar> 1242 template <typename sourcechar, typename sinkchar>
1258 INLINE(static void CopyCharsUnsigned(sinkchar* dest, 1243 INLINE(static void CopyCharsUnsigned(sinkchar* dest,
1259 const sourcechar* src, 1244 const sourcechar* src,
1260 int chars)); 1245 int chars));
1261 #if defined(V8_HOST_ARCH_ARM) 1246 #if defined(V8_HOST_ARCH_ARM)
1262 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); 1247 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars));
1263 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars)); 1248 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars));
1264 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); 1249 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars));
1265 #elif defined(V8_HOST_ARCH_MIPS) 1250 #elif defined(V8_HOST_ARCH_MIPS)
1266 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars)); 1251 INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars));
1267 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars)); 1252 INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars));
1268 #endif 1253 #endif
1269 1254
1270 // Copy from ASCII/16bit chars to ASCII/16bit chars. 1255 // Copy from 8bit/16bit chars to 8bit/16bit chars.
1271 template <typename sourcechar, typename sinkchar> 1256 template <typename sourcechar, typename sinkchar>
1272 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars)); 1257 INLINE(void CopyChars(sinkchar* dest, const sourcechar* src, int chars));
1273 1258
1274 template<typename sourcechar, typename sinkchar> 1259 template<typename sourcechar, typename sinkchar>
1275 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { 1260 void CopyChars(sinkchar* dest, const sourcechar* src, int chars) {
1276 DCHECK(sizeof(sourcechar) <= 2); 1261 DCHECK(sizeof(sourcechar) <= 2);
1277 DCHECK(sizeof(sinkchar) <= 2); 1262 DCHECK(sizeof(sinkchar) <= 2);
1278 if (sizeof(sinkchar) == 1) { 1263 if (sizeof(sinkchar) == 1) {
1279 if (sizeof(sourcechar) == 1) { 1264 if (sizeof(sourcechar) == 1) {
1280 CopyCharsUnsigned(reinterpret_cast<uint8_t*>(dest), 1265 CopyCharsUnsigned(reinterpret_cast<uint8_t*>(dest),
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 // Takes the address of the limit variable in order to find out where 1477 // Takes the address of the limit variable in order to find out where
1493 // the top of stack is right now. 1478 // the top of stack is right now.
1494 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); 1479 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit);
1495 return limit; 1480 return limit;
1496 } 1481 }
1497 1482
1498 } // namespace internal 1483 } // namespace internal
1499 } // namespace v8 1484 } // namespace v8
1500 1485
1501 #endif // V8_UTILS_H_ 1486 #endif // V8_UTILS_H_
OLDNEW
« src/jsregexp.cc ('K') | « src/uri.js ('k') | src/vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698