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

Unified Diff: src/objects.h

Issue 5963003: Clean up is-ASCII checks. (Closed)
Patch Set: Created 10 years 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 side-by-side diff with in-line comments
Download patch
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index c5fda7d0385d10d299754204a1c79c9d8b3ef33a..fdebd1f19dde2dc194d641ea4f8561857167204e 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -5245,6 +5245,34 @@ class String: public HeapObject {
int from,
int to);
+ static inline bool IsAscii(const char* chars, int length) {
+ const char* limit = chars + length;
+#ifdef V8_HOST_CAN_READ_UNALIGNED
+ ASSERT(kMaxAsciiCharCode == 0x7F);
+ const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
+ while (chars <= limit - sizeof(uintptr_t)) {
+ if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
+ return false;
+ }
+ chars += sizeof(uintptr_t);
+ }
+#endif
+ while (chars < limit) {
+ if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false;
+ ++chars;
+ }
+ return true;
+ }
+
+ static inline bool IsAscii(const uc16* chars, int length) {
+ const uc16* limit = chars + length;
+ while (chars < limit) {
+ if (*chars > kMaxAsciiCharCodeU) return false;
+ ++chars;
+ }
+ return true;
+ }
+
protected:
class ReadBlockBuffer {
public:
« src/heap.cc ('K') | « src/ia32/regexp-macro-assembler-ia32.cc ('k') | src/string-search.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698