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

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

Issue 663313003: Cleanup ConsStringIteratorOp. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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/string-stream.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 // 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 if (cons_string->IsConsString()) { 350 if (cons_string->IsConsString()) {
351 return AccumulateStats(ConsString::cast(*cons_string), stats); 351 return AccumulateStats(ConsString::cast(*cons_string), stats);
352 } 352 }
353 // This string got flattened by gc. 353 // This string got flattened by gc.
354 stats->chars_ += cons_string->length(); 354 stats->chars_ += cons_string->length();
355 } 355 }
356 356
357 357
358 void AccumulateStatsWithOperator( 358 void AccumulateStatsWithOperator(
359 ConsString* cons_string, ConsStringStats* stats) { 359 ConsString* cons_string, ConsStringStats* stats) {
360 ConsStringIteratorOp op(cons_string); 360 ConsStringIterator iter(cons_string);
361 String* string; 361 String* string;
362 int offset; 362 int offset;
363 while (NULL != (string = op.Next(&offset))) { 363 while (NULL != (string = iter.Next(&offset))) {
364 // Accumulate stats. 364 // Accumulate stats.
365 CHECK_EQ(0, offset); 365 CHECK_EQ(0, offset);
366 stats->leaves_++; 366 stats->leaves_++;
367 stats->chars_ += string->length(); 367 stats->chars_ += string->length();
368 } 368 }
369 } 369 }
370 370
371 371
372 void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) { 372 void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) {
373 // Verify basic data. 373 // Verify basic data.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 517
518 static Handle<String> ConstructBalanced( 518 static Handle<String> ConstructBalanced(
519 ConsStringGenerationData* data, int depth = DEEP_DEPTH) { 519 ConsStringGenerationData* data, int depth = DEEP_DEPTH) {
520 Handle<String> string = ConstructBalancedHelper(data, 0, depth); 520 Handle<String> string = ConstructBalancedHelper(data, 0, depth);
521 data->stats_.leaves_ = 521 data->stats_.leaves_ =
522 data->stats_.left_traversals_ + data->stats_.right_traversals_ + 2; 522 data->stats_.left_traversals_ + data->stats_.right_traversals_ + 2;
523 return string; 523 return string;
524 } 524 }
525 525
526 526
527 static ConsStringIteratorOp cons_string_iterator_op_1;
528 static ConsStringIteratorOp cons_string_iterator_op_2;
529
530 static void Traverse(Handle<String> s1, Handle<String> s2) { 527 static void Traverse(Handle<String> s1, Handle<String> s2) {
531 int i = 0; 528 int i = 0;
532 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1); 529 StringCharacterStream character_stream_1(*s1);
533 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2); 530 StringCharacterStream character_stream_2(*s2);
534 while (character_stream_1.HasMore()) { 531 while (character_stream_1.HasMore()) {
535 CHECK(character_stream_2.HasMore()); 532 CHECK(character_stream_2.HasMore());
536 uint16_t c = character_stream_1.GetNext(); 533 uint16_t c = character_stream_1.GetNext();
537 CHECK_EQ(c, character_stream_2.GetNext()); 534 CHECK_EQ(c, character_stream_2.GetNext());
538 i++; 535 i++;
539 } 536 }
540 CHECK(!character_stream_1.HasMore()); 537 CHECK(!character_stream_1.HasMore());
541 CHECK(!character_stream_2.HasMore()); 538 CHECK(!character_stream_2.HasMore());
542 CHECK_EQ(s1->length(), i); 539 CHECK_EQ(s1->length(), i);
543 CHECK_EQ(s2->length(), i); 540 CHECK_EQ(s2->length(), i);
544 } 541 }
545 542
546 543
547 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) { 544 static void TraverseFirst(Handle<String> s1, Handle<String> s2, int chars) {
548 int i = 0; 545 int i = 0;
549 StringCharacterStream character_stream_1(*s1, &cons_string_iterator_op_1); 546 StringCharacterStream character_stream_1(*s1);
550 StringCharacterStream character_stream_2(*s2, &cons_string_iterator_op_2); 547 StringCharacterStream character_stream_2(*s2);
551 while (character_stream_1.HasMore() && i < chars) { 548 while (character_stream_1.HasMore() && i < chars) {
552 CHECK(character_stream_2.HasMore()); 549 CHECK(character_stream_2.HasMore());
553 uint16_t c = character_stream_1.GetNext(); 550 uint16_t c = character_stream_1.GetNext();
554 CHECK_EQ(c, character_stream_2.GetNext()); 551 CHECK_EQ(c, character_stream_2.GetNext());
555 i++; 552 i++;
556 } 553 }
557 s1->Get(s1->length() - 1); 554 s1->Get(s1->length() - 1);
558 s2->Get(s2->length() - 1); 555 s2->Get(s2->length() - 1);
559 } 556 }
560 557
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 CHECK(cons_string->IsConsString()); 606 CHECK(cons_string->IsConsString());
610 // TODO(dcarney) Test stream reset as well. 607 // TODO(dcarney) Test stream reset as well.
611 int length = flat_string->length(); 608 int length = flat_string->length();
612 // Iterate start search in multiple places in the string. 609 // Iterate start search in multiple places in the string.
613 int outer_iterations = length > 20 ? 20 : length; 610 int outer_iterations = length > 20 ? 20 : length;
614 for (int j = 0; j <= outer_iterations; j++) { 611 for (int j = 0; j <= outer_iterations; j++) {
615 int offset = length * j / outer_iterations; 612 int offset = length * j / outer_iterations;
616 if (offset < 0) offset = 0; 613 if (offset < 0) offset = 0;
617 // Want to test the offset == length case. 614 // Want to test the offset == length case.
618 if (offset > length) offset = length; 615 if (offset > length) offset = length;
619 StringCharacterStream flat_stream( 616 StringCharacterStream flat_stream(flat_string, offset);
620 flat_string, &cons_string_iterator_op_1, offset); 617 StringCharacterStream cons_stream(cons_string, offset);
621 StringCharacterStream cons_stream(
622 cons_string, &cons_string_iterator_op_2, offset);
623 for (int i = offset; i < length; i++) { 618 for (int i = offset; i < length; i++) {
624 uint16_t c = flat_string->Get(i); 619 uint16_t c = flat_string->Get(i);
625 CHECK(flat_stream.HasMore()); 620 CHECK(flat_stream.HasMore());
626 CHECK(cons_stream.HasMore()); 621 CHECK(cons_stream.HasMore());
627 CHECK_EQ(c, flat_stream.GetNext()); 622 CHECK_EQ(c, flat_stream.GetNext());
628 CHECK_EQ(c, cons_stream.GetNext()); 623 CHECK_EQ(c, cons_stream.GetNext());
629 } 624 }
630 CHECK(!flat_stream.HasMore()); 625 CHECK(!flat_stream.HasMore());
631 CHECK(!cons_stream.HasMore()); 626 CHECK(!cons_stream.HasMore());
632 } 627 }
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 CHECK(isolate->has_pending_exception()); \ 1451 CHECK(isolate->has_pending_exception()); \
1457 isolate->clear_pending_exception(); \ 1452 isolate->clear_pending_exception(); \
1458 dummy.Dispose(); \ 1453 dummy.Dispose(); \
1459 } 1454 }
1460 1455
1461 INVALID_STRING_TEST(NewStringFromAscii, char) 1456 INVALID_STRING_TEST(NewStringFromAscii, char)
1462 INVALID_STRING_TEST(NewStringFromUtf8, char) 1457 INVALID_STRING_TEST(NewStringFromUtf8, char)
1463 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) 1458 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t)
1464 1459
1465 #undef INVALID_STRING_TEST 1460 #undef INVALID_STRING_TEST
OLDNEW
« no previous file with comments | « src/string-stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698