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

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

Issue 7374002: Refactor allocation policies. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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 | « test/cctest/test-list.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 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } 460 }
461 461
462 462
463 static bool NotWord(uc16 c) { 463 static bool NotWord(uc16 c) {
464 return !IsRegExpWord(c); 464 return !IsRegExpWord(c);
465 } 465 }
466 466
467 467
468 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) { 468 static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) {
469 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); 469 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT);
470 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); 470 ZoneList<CharacterRange>* ranges = ZoneList<CharacterRange>::New(ZONE, 2);
471 CharacterRange::AddClassEscape(c, ranges); 471 CharacterRange::AddClassEscape(c, ranges);
472 for (unsigned i = 0; i < (1 << 16); i++) { 472 for (unsigned i = 0; i < (1 << 16); i++) {
473 bool in_class = false; 473 bool in_class = false;
474 for (int j = 0; !in_class && j < ranges->length(); j++) { 474 for (int j = 0; !in_class && j < ranges->length(); j++) {
475 CharacterRange& range = ranges->at(j); 475 CharacterRange& range = ranges->at(j);
476 in_class = (range.from() <= i && i <= range.to()); 476 in_class = (range.from() <= i && i <= range.to());
477 } 477 }
478 CHECK_EQ(pred(i), in_class); 478 CHECK_EQ(pred(i), in_class);
479 } 479 }
480 } 480 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 547
548 static unsigned PseudoRandom(int i, int j) { 548 static unsigned PseudoRandom(int i, int j) {
549 return ~(~((i * 781) ^ (j * 329))); 549 return ~(~((i * 781) ^ (j * 329)));
550 } 550 }
551 551
552 552
553 TEST(SplayTreeSimple) { 553 TEST(SplayTreeSimple) {
554 v8::internal::V8::Initialize(NULL); 554 v8::internal::V8::Initialize(NULL);
555 static const unsigned kLimit = 1000; 555 static const unsigned kLimit = 1000;
556 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 556 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
557 ZoneSplayTree<TestConfig> tree; 557 ZoneSplayTree<TestConfig> tree(ZONE);
558 bool seen[kLimit]; 558 bool seen[kLimit];
559 for (unsigned i = 0; i < kLimit; i++) seen[i] = false; 559 for (unsigned i = 0; i < kLimit; i++) seen[i] = false;
560 #define CHECK_MAPS_EQUAL() do { \ 560 #define CHECK_MAPS_EQUAL() do { \
561 for (unsigned k = 0; k < kLimit; k++) \ 561 for (unsigned k = 0; k < kLimit; k++) \
562 CHECK_EQ(seen[k], tree.Find(k, &loc)); \ 562 CHECK_EQ(seen[k], tree.Find(k, &loc)); \
563 } while (false) 563 } while (false)
564 for (int i = 0; i < 50; i++) { 564 for (int i = 0; i < 50; i++) {
565 for (int j = 0; j < 50; j++) { 565 for (int j = 0; j < 50; j++) {
566 unsigned next = PseudoRandom(i, j) % kLimit; 566 unsigned next = PseudoRandom(i, j) % kLimit;
567 if (seen[next]) { 567 if (seen[next]) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 for (int j = 0; j < 2 * kRangeSize; j++) { 615 for (int j = 0; j < 2 * kRangeSize; j++) {
616 range[j] = PseudoRandom(i + 25, j + 87) % kLimit; 616 range[j] = PseudoRandom(i + 25, j + 87) % kLimit;
617 } 617 }
618 range.Sort(); 618 range.Sort();
619 for (int j = 1; j < 2 * kRangeSize; j++) { 619 for (int j = 1; j < 2 * kRangeSize; j++) {
620 CHECK(range[j-1] <= range[j]); 620 CHECK(range[j-1] <= range[j]);
621 } 621 }
622 } 622 }
623 // Enter test data into dispatch table. 623 // Enter test data into dispatch table.
624 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 624 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
625 DispatchTable table; 625 DispatchTable table(ZONE);
626 for (int i = 0; i < kRangeCount; i++) { 626 for (int i = 0; i < kRangeCount; i++) {
627 uc16* range = ranges[i]; 627 uc16* range = ranges[i];
628 for (int j = 0; j < 2 * kRangeSize; j += 2) 628 for (int j = 0; j < 2 * kRangeSize; j += 2)
629 table.AddRange(CharacterRange(range[j], range[j + 1]), i); 629 table.AddRange(CharacterRange(range[j], range[j + 1]), i);
630 } 630 }
631 // Check that the table looks as we would expect 631 // Check that the table looks as we would expect
632 for (int p = 0; p < kLimit; p++) { 632 for (int p = 0; p < kLimit; p++) {
633 OutSet* outs = table.Get(p); 633 OutSet* outs = table.Get(p);
634 for (int j = 0; j < kRangeCount; j++) { 634 for (int j = 0; j < kRangeCount; j++) {
635 uc16* range = ranges[j]; 635 uc16* range = ranges[j];
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 #endif // V8_INTERPRETED_REGEXP 1378 #endif // V8_INTERPRETED_REGEXP
1379 1379
1380 1380
1381 TEST(AddInverseToTable) { 1381 TEST(AddInverseToTable) {
1382 v8::internal::V8::Initialize(NULL); 1382 v8::internal::V8::Initialize(NULL);
1383 static const int kLimit = 1000; 1383 static const int kLimit = 1000;
1384 static const int kRangeCount = 16; 1384 static const int kRangeCount = 16;
1385 for (int t = 0; t < 10; t++) { 1385 for (int t = 0; t < 10; t++) {
1386 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 1386 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
1387 ZoneList<CharacterRange>* ranges = 1387 ZoneList<CharacterRange>* ranges =
1388 new ZoneList<CharacterRange>(kRangeCount); 1388 ZoneList<CharacterRange>::New(ZONE, kRangeCount);
1389 for (int i = 0; i < kRangeCount; i++) { 1389 for (int i = 0; i < kRangeCount; i++) {
1390 int from = PseudoRandom(t + 87, i + 25) % kLimit; 1390 int from = PseudoRandom(t + 87, i + 25) % kLimit;
1391 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20)); 1391 int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20));
1392 if (to > kLimit) to = kLimit; 1392 if (to > kLimit) to = kLimit;
1393 ranges->Add(CharacterRange(from, to)); 1393 ranges->Add(CharacterRange(from, to));
1394 } 1394 }
1395 DispatchTable table; 1395 DispatchTable table(ZONE);
1396 DispatchTableConstructor cons(&table, false); 1396 DispatchTableConstructor cons(ZONE, &table, false);
1397 cons.set_choice_index(0); 1397 cons.set_choice_index(0);
1398 cons.AddInverse(ranges); 1398 cons.AddInverse(ranges);
1399 for (int i = 0; i < kLimit; i++) { 1399 for (int i = 0; i < kLimit; i++) {
1400 bool is_on = false; 1400 bool is_on = false;
1401 for (int j = 0; !is_on && j < kRangeCount; j++) 1401 for (int j = 0; !is_on && j < kRangeCount; j++)
1402 is_on = ranges->at(j).Contains(i); 1402 is_on = ranges->at(j).Contains(i);
1403 OutSet* set = table.Get(i); 1403 OutSet* set = table.Get(i);
1404 CHECK_EQ(is_on, set->Get(0) == false); 1404 CHECK_EQ(is_on, set->Get(0) == false);
1405 } 1405 }
1406 } 1406 }
1407 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 1407 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
1408 ZoneList<CharacterRange>* ranges = 1408 ZoneList<CharacterRange>* ranges =
1409 new ZoneList<CharacterRange>(1); 1409 ZoneList<CharacterRange>::New(ZONE, 1);
1410 ranges->Add(CharacterRange(0xFFF0, 0xFFFE)); 1410 ranges->Add(CharacterRange(0xFFF0, 0xFFFE));
1411 DispatchTable table; 1411 DispatchTable table(ZONE);
1412 DispatchTableConstructor cons(&table, false); 1412 DispatchTableConstructor cons(ZONE, &table, false);
1413 cons.set_choice_index(0); 1413 cons.set_choice_index(0);
1414 cons.AddInverse(ranges); 1414 cons.AddInverse(ranges);
1415 CHECK(!table.Get(0xFFFE)->Get(0)); 1415 CHECK(!table.Get(0xFFFE)->Get(0));
1416 CHECK(table.Get(0xFFFF)->Get(0)); 1416 CHECK(table.Get(0xFFFF)->Get(0));
1417 } 1417 }
1418 1418
1419 1419
1420 static uc32 canonicalize(uc32 c) { 1420 static uc32 canonicalize(uc32 c) {
1421 unibrow::uchar canon[unibrow::Ecma262Canonicalize::kMaxWidth]; 1421 unibrow::uchar canon[unibrow::Ecma262Canonicalize::kMaxWidth];
1422 int count = unibrow::Ecma262Canonicalize::Convert(c, '\0', canon, NULL); 1422 int count = unibrow::Ecma262Canonicalize::Convert(c, '\0', canon, NULL);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k])); 1512 CHECK_EQ(static_cast<int>(chars[k]), static_cast<int>(chars2[k]));
1513 } 1513 }
1514 } 1514 }
1515 } 1515 }
1516 1516
1517 1517
1518 static void TestRangeCaseIndependence(CharacterRange input, 1518 static void TestRangeCaseIndependence(CharacterRange input,
1519 Vector<CharacterRange> expected) { 1519 Vector<CharacterRange> expected) {
1520 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 1520 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
1521 int count = expected.length(); 1521 int count = expected.length();
1522 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(count); 1522 ZoneList<CharacterRange>* list = ZoneList<CharacterRange>::New(ZONE, count);
1523 input.AddCaseEquivalents(list, false); 1523 input.AddCaseEquivalents(list, false);
1524 CHECK_EQ(count, list->length()); 1524 CHECK_EQ(count, list->length());
1525 for (int i = 0; i < list->length(); i++) { 1525 for (int i = 0; i < list->length(); i++) {
1526 CHECK_EQ(expected[i].from(), list->at(i).from()); 1526 CHECK_EQ(expected[i].from(), list->at(i).from());
1527 CHECK_EQ(expected[i].to(), list->at(i).to()); 1527 CHECK_EQ(expected[i].to(), list->at(i).to());
1528 } 1528 }
1529 } 1529 }
1530 1530
1531 1531
1532 static void TestSimpleRangeCaseIndependence(CharacterRange input, 1532 static void TestSimpleRangeCaseIndependence(CharacterRange input,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 if (range.from() <= c && c <= range.to()) 1575 if (range.from() <= c && c <= range.to())
1576 return true; 1576 return true;
1577 } 1577 }
1578 return false; 1578 return false;
1579 } 1579 }
1580 1580
1581 1581
1582 TEST(CharClassDifference) { 1582 TEST(CharClassDifference) {
1583 v8::internal::V8::Initialize(NULL); 1583 v8::internal::V8::Initialize(NULL);
1584 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 1584 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
1585 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); 1585 ZoneList<CharacterRange>* base = ZoneList<CharacterRange>::New(ZONE, 1);
1586 base->Add(CharacterRange::Everything()); 1586 base->Add(CharacterRange::Everything());
1587 Vector<const uc16> overlay = CharacterRange::GetWordBounds(); 1587 Vector<const uc16> overlay = CharacterRange::GetWordBounds();
1588 ZoneList<CharacterRange>* included = NULL; 1588 ZoneList<CharacterRange>* included = NULL;
1589 ZoneList<CharacterRange>* excluded = NULL; 1589 ZoneList<CharacterRange>* excluded = NULL;
1590 CharacterRange::Split(base, overlay, &included, &excluded); 1590 CharacterRange::Split(ZONE, base, overlay, &included, &excluded);
1591 for (int i = 0; i < (1 << 16); i++) { 1591 for (int i = 0; i < (1 << 16); i++) {
1592 bool in_base = InClass(i, base); 1592 bool in_base = InClass(i, base);
1593 if (in_base) { 1593 if (in_base) {
1594 bool in_overlay = false; 1594 bool in_overlay = false;
1595 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { 1595 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) {
1596 if (overlay[j] <= i && i <= overlay[j+1]) 1596 if (overlay[j] <= i && i <= overlay[j+1])
1597 in_overlay = true; 1597 in_overlay = true;
1598 } 1598 }
1599 CHECK_EQ(in_overlay, InClass(i, included)); 1599 CHECK_EQ(in_overlay, InClass(i, included));
1600 CHECK_EQ(!in_overlay, InClass(i, excluded)); 1600 CHECK_EQ(!in_overlay, InClass(i, excluded));
1601 } else { 1601 } else {
1602 CHECK(!InClass(i, included)); 1602 CHECK(!InClass(i, included));
1603 CHECK(!InClass(i, excluded)); 1603 CHECK(!InClass(i, excluded));
1604 } 1604 }
1605 } 1605 }
1606 } 1606 }
1607 1607
1608 1608
1609 TEST(CanonicalizeCharacterSets) { 1609 TEST(CanonicalizeCharacterSets) {
1610 v8::internal::V8::Initialize(NULL); 1610 v8::internal::V8::Initialize(NULL);
1611 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT); 1611 ZoneScope scope(Isolate::Current(), DELETE_ON_EXIT);
1612 ZoneList<CharacterRange>* list = new ZoneList<CharacterRange>(4); 1612 ZoneList<CharacterRange>* list = ZoneList<CharacterRange>::New(ZONE, 4);
1613 CharacterSet set(list); 1613 CharacterSet set(list);
1614 1614
1615 list->Add(CharacterRange(10, 20)); 1615 list->Add(CharacterRange(10, 20));
1616 list->Add(CharacterRange(30, 40)); 1616 list->Add(CharacterRange(30, 40));
1617 list->Add(CharacterRange(50, 60)); 1617 list->Add(CharacterRange(50, 60));
1618 set.Canonicalize(); 1618 set.Canonicalize();
1619 ASSERT_EQ(3, list->length()); 1619 ASSERT_EQ(3, list->length());
1620 ASSERT_EQ(10, list->at(0).from()); 1620 ASSERT_EQ(10, list->at(0).from());
1621 ASSERT_EQ(20, list->at(0).to()); 1621 ASSERT_EQ(20, list->at(0).to());
1622 ASSERT_EQ(30, list->at(1).from()); 1622 ASSERT_EQ(30, list->at(1).from());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 if (range.from() <= value && value <= range.to()) { 1673 if (range.from() <= value && value <= range.to()) {
1674 return true; 1674 return true;
1675 } 1675 }
1676 } 1676 }
1677 return false; 1677 return false;
1678 } 1678 }
1679 1679
1680 TEST(CharacterRangeMerge) { 1680 TEST(CharacterRangeMerge) {
1681 v8::internal::V8::Initialize(NULL); 1681 v8::internal::V8::Initialize(NULL);
1682 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); 1682 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT);
1683 ZoneList<CharacterRange> l1(4); 1683 ZoneList<CharacterRange> l1(ZONE, 4);
1684 ZoneList<CharacterRange> l2(4); 1684 ZoneList<CharacterRange> l2(ZONE, 4);
1685 // Create all combinations of intersections of ranges, both singletons and 1685 // Create all combinations of intersections of ranges, both singletons and
1686 // longer. 1686 // longer.
1687 1687
1688 int offset = 0; 1688 int offset = 0;
1689 1689
1690 // The five kinds of singleton intersections: 1690 // The five kinds of singleton intersections:
1691 // X 1691 // X
1692 // Y - outside before 1692 // Y - outside before
1693 // Y - outside touching start 1693 // Y - outside touching start
1694 // Y - overlap 1694 // Y - overlap
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 l1.Add(CharacterRange::Range(offset + 31, offset + 52)); 1752 l1.Add(CharacterRange::Range(offset + 31, offset + 52));
1753 for (int i = 0; i < 6; i++) { 1753 for (int i = 0; i < 6; i++) {
1754 l2.Add(CharacterRange::Range(offset + 2, offset + 5)); 1754 l2.Add(CharacterRange::Range(offset + 2, offset + 5));
1755 l2.Add(CharacterRange::Singleton(offset + 8)); 1755 l2.Add(CharacterRange::Singleton(offset + 8));
1756 offset += 9; 1756 offset += 9;
1757 } 1757 }
1758 1758
1759 ASSERT(CharacterRange::IsCanonical(&l1)); 1759 ASSERT(CharacterRange::IsCanonical(&l1));
1760 ASSERT(CharacterRange::IsCanonical(&l2)); 1760 ASSERT(CharacterRange::IsCanonical(&l2));
1761 1761
1762 ZoneList<CharacterRange> first_only(4); 1762 ZoneList<CharacterRange> first_only(ZONE, 4);
1763 ZoneList<CharacterRange> second_only(4); 1763 ZoneList<CharacterRange> second_only(ZONE, 4);
1764 ZoneList<CharacterRange> both(4); 1764 ZoneList<CharacterRange> both(ZONE, 4);
1765 1765
1766 // Merge one direction. 1766 // Merge one direction.
1767 CharacterRange::Merge(&l1, &l2, &first_only, &second_only, &both); 1767 CharacterRange::Merge(&l1, &l2, &first_only, &second_only, &both);
1768 1768
1769 CHECK(CharacterRange::IsCanonical(&first_only)); 1769 CHECK(CharacterRange::IsCanonical(&first_only));
1770 CHECK(CharacterRange::IsCanonical(&second_only)); 1770 CHECK(CharacterRange::IsCanonical(&second_only));
1771 CHECK(CharacterRange::IsCanonical(&both)); 1771 CHECK(CharacterRange::IsCanonical(&both));
1772 1772
1773 for (uc16 i = 0; i < offset; i++) { 1773 for (uc16 i = 0; i < offset; i++) {
1774 bool in_first = CharacterInSet(&l1, i); 1774 bool in_first = CharacterInSet(&l1, i);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 1806
1807 CHECK(CharacterRange::IsCanonical(&both)); 1807 CHECK(CharacterRange::IsCanonical(&both));
1808 1808
1809 for (uc16 i = 0; i < offset; i++) { 1809 for (uc16 i = 0; i < offset; i++) {
1810 bool in_first = CharacterInSet(&l1, i); 1810 bool in_first = CharacterInSet(&l1, i);
1811 bool in_second = CharacterInSet(&l2, i); 1811 bool in_second = CharacterInSet(&l2, i);
1812 CHECK((in_first && in_second) == CharacterInSet(&both, i)); 1812 CHECK((in_first && in_second) == CharacterInSet(&both, i));
1813 } 1813 }
1814 1814
1815 // Merge into same set. 1815 // Merge into same set.
1816 ZoneList<CharacterRange> all(4); 1816 ZoneList<CharacterRange> all(ZONE, 4);
1817 CharacterRange::Merge(&l1, &l2, &all, &all, &all); 1817 CharacterRange::Merge(&l1, &l2, &all, &all, &all);
1818 1818
1819 CHECK(CharacterRange::IsCanonical(&all)); 1819 CHECK(CharacterRange::IsCanonical(&all));
1820 1820
1821 for (uc16 i = 0; i < offset; i++) { 1821 for (uc16 i = 0; i < offset; i++) {
1822 bool in_first = CharacterInSet(&l1, i); 1822 bool in_first = CharacterInSet(&l1, i);
1823 bool in_second = CharacterInSet(&l2, i); 1823 bool in_second = CharacterInSet(&l2, i);
1824 CHECK((in_first || in_second) == CharacterInSet(&all, i)); 1824 CHECK((in_first || in_second) == CharacterInSet(&all, i));
1825 } 1825 }
1826 } 1826 }
1827 1827
1828 1828
1829 TEST(Graph) { 1829 TEST(Graph) {
1830 V8::Initialize(NULL); 1830 V8::Initialize(NULL);
1831 Execute("\\b\\w+\\b", false, true, true); 1831 Execute("\\b\\w+\\b", false, true, true);
1832 } 1832 }
OLDNEW
« no previous file with comments | « test/cctest/test-list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698