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

Side by Side Diff: test/cctest/test-strings.cc

Issue 11638037: Remove most uses of StringInputBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: cleanup Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8conversions.cc ('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 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 514 }
515 515
516 516
517 static StringInputBuffer buffer; 517 static StringInputBuffer buffer;
518 static ConsStringIteratorOp cons_string_iterator_op_1; 518 static ConsStringIteratorOp cons_string_iterator_op_1;
519 static ConsStringIteratorOp cons_string_iterator_op_2; 519 static ConsStringIteratorOp cons_string_iterator_op_2;
520 520
521 static void Traverse(Handle<String> s1, Handle<String> s2) { 521 static void Traverse(Handle<String> s1, Handle<String> s2) {
522 int i = 0; 522 int i = 0;
523 buffer.Reset(*s1); 523 buffer.Reset(*s1);
524 StringCharacterStream character_stream_1(*s1, 0, &cons_string_iterator_op_1); 524 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1);
525 StringCharacterStream character_stream_2(*s2, 0, &cons_string_iterator_op_2); 525 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2);
526 StringInputBuffer buffer2(*s2); 526 StringInputBuffer buffer2(*s2);
527 while (buffer.has_more()) { 527 while (buffer.has_more()) {
528 CHECK(buffer2.has_more()); 528 CHECK(buffer2.has_more());
529 CHECK(character_stream_1.HasMore()); 529 CHECK(character_stream_1.HasMore());
530 CHECK(character_stream_2.HasMore()); 530 CHECK(character_stream_2.HasMore());
531 uint16_t c = buffer.GetNext(); 531 uint16_t c = buffer.GetNext();
532 CHECK_EQ(c, buffer2.GetNext()); 532 CHECK_EQ(c, buffer2.GetNext());
533 CHECK_EQ(c, character_stream_1.GetNext()); 533 CHECK_EQ(c, character_stream_1.GetNext());
534 CHECK_EQ(c, character_stream_2.GetNext()); 534 CHECK_EQ(c, character_stream_2.GetNext());
535 i++; 535 i++;
536 } 536 }
537 CHECK(!character_stream_1.HasMore()); 537 CHECK(!character_stream_1.HasMore());
538 CHECK(!character_stream_2.HasMore()); 538 CHECK(!character_stream_2.HasMore());
539 CHECK_EQ(s1->length(), i); 539 CHECK_EQ(s1->length(), i);
540 CHECK_EQ(s2->length(), i); 540 CHECK_EQ(s2->length(), i);
541 } 541 }
542 542
543 543
544 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { 544 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) {
545 int i = 0; 545 int i = 0;
546 buffer.Reset(*s1); 546 buffer.Reset(*s1);
547 StringInputBuffer buffer2(*s2); 547 StringInputBuffer buffer2(*s2);
548 StringCharacterStream character_stream_1(*s1, 0, &cons_string_iterator_op_1); 548 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1);
549 StringCharacterStream character_stream_2(*s2, 0, &cons_string_iterator_op_2); 549 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2);
550 while (buffer.has_more() && i < chars) { 550 while (buffer.has_more() && i < chars) {
551 CHECK(buffer2.has_more()); 551 CHECK(buffer2.has_more());
552 CHECK(character_stream_1.HasMore()); 552 CHECK(character_stream_1.HasMore());
553 CHECK(character_stream_2.HasMore()); 553 CHECK(character_stream_2.HasMore());
554 uint16_t c = buffer.GetNext(); 554 uint16_t c = buffer.GetNext();
555 CHECK_EQ(c, buffer2.GetNext()); 555 CHECK_EQ(c, buffer2.GetNext());
556 CHECK_EQ(c, character_stream_1.GetNext()); 556 CHECK_EQ(c, character_stream_1.GetNext());
557 CHECK_EQ(c, character_stream_2.GetNext()); 557 CHECK_EQ(c, character_stream_2.GetNext());
558 i++; 558 i++;
559 } 559 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 // TODO(dcarney) Test stream reset as well. 614 // TODO(dcarney) Test stream reset as well.
615 int length = flat_string->length(); 615 int length = flat_string->length();
616 // Iterate start search in multiple places in the string. 616 // Iterate start search in multiple places in the string.
617 int outer_iterations = length > 20 ? 20 : length; 617 int outer_iterations = length > 20 ? 20 : length;
618 for (int j = 0; j <= outer_iterations; j++) { 618 for (int j = 0; j <= outer_iterations; j++) {
619 int offset = length * j / outer_iterations; 619 int offset = length * j / outer_iterations;
620 if (offset < 0) offset = 0; 620 if (offset < 0) offset = 0;
621 // Want to test the offset == length case. 621 // Want to test the offset == length case.
622 if (offset > length) offset = length; 622 if (offset > length) offset = length;
623 StringCharacterStream flat_stream( 623 StringCharacterStream flat_stream(
624 flat_string, (unsigned) offset, &cons_string_iterator_op_1); 624 flat_string, &cons_string_iterator_op_1, (unsigned) offset);
625 StringCharacterStream cons_stream( 625 StringCharacterStream cons_stream(
626 cons_string, (unsigned) offset, &cons_string_iterator_op_2); 626 cons_string, &cons_string_iterator_op_2, (unsigned) offset);
627 for (int i = offset; i < length; i++) { 627 for (int i = offset; i < length; i++) {
628 uint16_t c = flat_string->Get(i); 628 uint16_t c = flat_string->Get(i);
629 CHECK(flat_stream.HasMore()); 629 CHECK(flat_stream.HasMore());
630 CHECK(cons_stream.HasMore()); 630 CHECK(cons_stream.HasMore());
631 CHECK_EQ(c, flat_stream.GetNext()); 631 CHECK_EQ(c, flat_stream.GetNext());
632 CHECK_EQ(c, cons_stream.GetNext()); 632 CHECK_EQ(c, cons_stream.GetNext());
633 } 633 }
634 CHECK(!flat_stream.HasMore()); 634 CHECK(!flat_stream.HasMore());
635 CHECK(!cons_stream.HasMore()); 635 CHECK(!cons_stream.HasMore());
636 } 636 }
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 1281
1282 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); 1282 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80");
1283 CHECK(expected->Equals(result)); 1283 CHECK(expected->Equals(result));
1284 } 1284 }
1285 1285
1286 1286
1287 TEST(IsAscii) { 1287 TEST(IsAscii) {
1288 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); 1288 CHECK(String::IsAscii(static_cast<char*>(NULL), 0));
1289 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); 1289 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0));
1290 } 1290 }
OLDNEW
« no previous file with comments | « src/v8conversions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698