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

Side by Side Diff: src/objects.h

Issue 11194053: Keep track of the first non-ascii word/char to avoid redoing the work. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 8 years, 2 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
« no previous file with comments | « src/heap-inl.h ('k') | no next file » | 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 // 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 7395 matching lines...) Expand 10 before | Expand all | Expand 10 after
7406 unsigned* remaining, 7406 unsigned* remaining,
7407 unsigned* offset); 7407 unsigned* offset);
7408 7408
7409 // Helper function for flattening strings. 7409 // Helper function for flattening strings.
7410 template <typename sinkchar> 7410 template <typename sinkchar>
7411 static void WriteToFlat(String* source, 7411 static void WriteToFlat(String* source,
7412 sinkchar* sink, 7412 sinkchar* sink,
7413 int from, 7413 int from,
7414 int to); 7414 int to);
7415 7415
7416 static inline bool IsAscii(const char* chars, int length) { 7416 // The return value may point to the first aligned word containing the
7417 // first non-ascii character, rather than directly to the non-ascii character.
7418 // If the return value is >= the passed length, the entire string was ASCII.
7419 static inline int NonAsciiStart(const char* chars, int length) {
7420 const char* start = chars;
7417 const char* limit = chars + length; 7421 const char* limit = chars + length;
7418 #ifdef V8_HOST_CAN_READ_UNALIGNED 7422 #ifdef V8_HOST_CAN_READ_UNALIGNED
7419 ASSERT(kMaxAsciiCharCode == 0x7F); 7423 ASSERT(kMaxAsciiCharCode == 0x7F);
7420 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; 7424 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
7421 while (chars + sizeof(uintptr_t) <= limit) { 7425 while (chars + sizeof(uintptr_t) <= limit) {
7422 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { 7426 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
7423 return false; 7427 return chars - start;
7424 } 7428 }
7425 chars += sizeof(uintptr_t); 7429 chars += sizeof(uintptr_t);
7426 } 7430 }
7427 #endif 7431 #endif
7428 while (chars < limit) { 7432 while (chars < limit) {
7429 if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; 7433 if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) {
7434 return chars - start;
7435 }
7430 ++chars; 7436 ++chars;
7431 } 7437 }
7432 return true; 7438 return chars - start;
7439 }
7440
7441 static inline bool IsAscii(const char* chars, int length) {
7442 return NonAsciiStart(chars, length) >= length;
7443 }
7444
7445 static inline int NonAsciiStart(const uc16* chars, int length) {
7446 const uc16* limit = chars + length;
7447 const uc16* start = chars;
7448 while (chars < limit) {
7449 if (*chars > kMaxAsciiCharCodeU) return chars - start;
7450 ++chars;
7451 }
7452 return chars - start;
7433 } 7453 }
7434 7454
7435 static inline bool IsAscii(const uc16* chars, int length) { 7455 static inline bool IsAscii(const uc16* chars, int length) {
7436 const uc16* limit = chars + length; 7456 return NonAsciiStart(chars, length) >= length;
7437 while (chars < limit) {
7438 if (*chars > kMaxAsciiCharCodeU) return false;
7439 ++chars;
7440 }
7441 return true;
7442 } 7457 }
7443 7458
7444 protected: 7459 protected:
7445 class ReadBlockBuffer { 7460 class ReadBlockBuffer {
7446 public: 7461 public:
7447 ReadBlockBuffer(unibrow::byte* util_buffer_, 7462 ReadBlockBuffer(unibrow::byte* util_buffer_,
7448 unsigned cursor_, 7463 unsigned cursor_,
7449 unsigned capacity_, 7464 unsigned capacity_,
7450 unsigned remaining_) : 7465 unsigned remaining_) :
7451 util_buffer(util_buffer_), 7466 util_buffer(util_buffer_),
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
8938 } else { 8953 } else {
8939 value &= ~(1 << bit_position); 8954 value &= ~(1 << bit_position);
8940 } 8955 }
8941 return value; 8956 return value;
8942 } 8957 }
8943 }; 8958 };
8944 8959
8945 } } // namespace v8::internal 8960 } } // namespace v8::internal
8946 8961
8947 #endif // V8_OBJECTS_H_ 8962 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/heap-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698