OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 // Check that we can traverse very deep stacks of ConsStrings using | 3 // Check that we can traverse very deep stacks of ConsStrings using |
4 // StringInputBuffer. Check that Get(int) works on very deep stacks | 4 // StringInputBuffer. Check that Get(int) works on very deep stacks |
5 // of ConsStrings. These operations may not be very fast, but they | 5 // of ConsStrings. These operations may not be very fast, but they |
6 // should be possible without getting errors due to too deep recursion. | 6 // should be possible without getting errors due to too deep recursion. |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "v8.h" | 10 #include "v8.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 Q[j] = Q[j - 3] ^ Q[j - 2] ^ phi ^ j; | 33 Q[j] = Q[j - 3] ^ Q[j - 2] ^ phi ^ j; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 uint32_t next() { | 37 uint32_t next() { |
38 uint64_t a = 18782; | 38 uint64_t a = 18782; |
39 uint32_t r = 0xfffffffe; | 39 uint32_t r = 0xfffffffe; |
40 i = (i + 1) & (kQSize-1); | 40 i = (i + 1) & (kQSize-1); |
41 uint64_t t = a * Q[i] + c; | 41 uint64_t t = a * Q[i] + c; |
42 c = (t >> 32); | 42 c = (t >> 32); |
43 uint32_t x = t + c; | 43 uint32_t x = static_cast<uint32_t>(t + c); |
44 if (x < c) { | 44 if (x < c) { |
45 x++; | 45 x++; |
46 c++; | 46 c++; |
47 } | 47 } |
48 return (Q[i] = r - x); | 48 return (Q[i] = r - x); |
49 } | 49 } |
50 | 50 |
51 uint32_t next(int max) { | 51 uint32_t next(int max) { |
52 return next() % max; | 52 return next() % max; |
53 } | 53 } |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 String* flat_string, String* cons_string) { | 628 String* flat_string, String* cons_string) { |
629 // Do not want to test ConString traversal on flat string. | 629 // Do not want to test ConString traversal on flat string. |
630 CHECK(flat_string->IsFlat()); | 630 CHECK(flat_string->IsFlat()); |
631 CHECK(!flat_string->IsConsString()); | 631 CHECK(!flat_string->IsConsString()); |
632 CHECK(cons_string->IsConsString()); | 632 CHECK(cons_string->IsConsString()); |
633 // TODO(dcarney) Test stream reset as well. | 633 // TODO(dcarney) Test stream reset as well. |
634 int length = flat_string->length(); | 634 int length = flat_string->length(); |
635 // Iterate start search in multiple places in the string. | 635 // Iterate start search in multiple places in the string. |
636 int outer_iterations = length > 20 ? 20 : length; | 636 int outer_iterations = length > 20 ? 20 : length; |
637 for (int j = 0; j <= outer_iterations; j++) { | 637 for (int j = 0; j <= outer_iterations; j++) { |
638 int offset = static_cast<double>(length)*j/outer_iterations; | 638 int offset = length * j / outer_iterations; |
639 if (offset < 0) offset = 0; | 639 if (offset < 0) offset = 0; |
640 // Want to test the offset == length case. | 640 // Want to test the offset == length case. |
641 if (offset > length) offset = length; | 641 if (offset > length) offset = length; |
642 StringCharacterStream flat_stream( | 642 StringCharacterStream flat_stream( |
643 flat_string, (unsigned) offset, &cons_string_iterator_op_1); | 643 flat_string, (unsigned) offset, &cons_string_iterator_op_1); |
644 StringCharacterStream cons_stream( | 644 StringCharacterStream cons_stream( |
645 cons_string, (unsigned) offset, &cons_string_iterator_op_2); | 645 cons_string, (unsigned) offset, &cons_string_iterator_op_2); |
646 for (int i = offset; i < length; i++) { | 646 for (int i = offset; i < length; i++) { |
647 uint16_t c = flat_string->Get(i); | 647 uint16_t c = flat_string->Get(i); |
648 CHECK(flat_stream.HasMore()); | 648 CHECK(flat_stream.HasMore()); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 | 1113 |
1114 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); | 1114 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); |
1115 CHECK(expected->Equals(result)); | 1115 CHECK(expected->Equals(result)); |
1116 } | 1116 } |
1117 | 1117 |
1118 | 1118 |
1119 TEST(IsAscii) { | 1119 TEST(IsAscii) { |
1120 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); | 1120 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); |
1121 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); | 1121 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); |
1122 } | 1122 } |
OLD | NEW |