Changeset 255125 in webkit
- Timestamp:
- Jan 25, 2020, 12:13:34 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/Source/WTF/ChangeLog ¶
r255120 r255125 1 2020-01-25 Mark Lam <mark.lam@apple.com> 2 3 Add some tests for dynamically allocated StaticStringImpls. 4 https://bugs.webkit.org/show_bug.cgi?id=206802 5 6 Reviewed by Darin Adler. 7 8 Removed some unnecessary explicit specialization of the charactersAreAllASCII() 9 template function. 10 11 * wtf/text/StringImpl.cpp: 12 (WTF::StringImpl::createFromLiteral): 13 (WTF::StringImpl::createStaticStringImpl): 14 1 15 2020-01-24 Mark Lam <mark.lam@apple.com> 2 16 -
TabularUnified trunk/Source/WTF/wtf/text/StringImpl.cpp ¶
r255120 r255125 157 157 { 158 158 ASSERT_WITH_MESSAGE(length, "Use StringImpl::empty() to create an empty string"); 159 ASSERT(charactersAreAllASCII <LChar>(reinterpret_cast<const LChar*>(characters), length));159 ASSERT(charactersAreAllASCII(reinterpret_cast<const LChar*>(characters), length)); 160 160 return adoptRef(*new StringImpl(reinterpret_cast<const LChar*>(characters), length, ConstructWithoutCopying)); 161 161 } … … 285 285 { 286 286 const LChar* lcharCharacters = reinterpret_cast<const LChar*>(characters); 287 ASSERT(charactersAreAllASCII <LChar>(lcharCharacters, length));287 ASSERT(charactersAreAllASCII(lcharCharacters, length)); 288 288 Ref<StringImpl> result = createInternal(lcharCharacters, length); 289 289 result->setHash(StringHasher::computeHashAndMaskTop8Bits(lcharCharacters, length)); -
TabularUnified trunk/Tools/ChangeLog ¶
r255123 r255125 1 2020-01-25 Mark Lam <mark.lam@apple.com> 2 3 Add some tests for dynamically allocated StaticStringImpls. 4 https://bugs.webkit.org/show_bug.cgi?id=206802 5 6 Reviewed by Darin Adler. 7 8 * TestWebKitAPI/Tests/WTF/StringImpl.cpp: 9 (TestWebKitAPI::doStaticStringImplTests): 10 (TestWebKitAPI::TEST): 11 1 12 2020-01-25 Aakash Jain <aakash_jain@apple.com> 2 13 -
TabularUnified trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp ¶
r246636 r255125 1 1 /* 2 * Copyright (C) 2012 , 2016Apple Inc. All rights reserved.2 * Copyright (C) 2012-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 687 687 }; 688 688 689 enum class StaticStringImplTestSet { 690 StaticallyAllocatedImpl, 691 DynamicallyAllocatedImpl 692 }; 693 694 static void doStaticStringImplTests(StaticStringImplTestSet testSet, String& hello, String& world, String& longer, String& hello2) 695 { 696 ASSERT_EQ(strlen("hello"), hello.length()); 697 ASSERT_EQ(strlen("world"), world.length()); 698 ASSERT_EQ(strlen("longer"), longer.length()); 699 ASSERT_EQ(strlen("hello"), hello2.length()); 700 701 ASSERT_TRUE(equal(hello, "hello")); 702 ASSERT_TRUE(equal(world, "world")); 703 ASSERT_TRUE(equal(longer, "longer")); 704 ASSERT_TRUE(equal(hello2, "hello")); 705 706 // Each StaticStringImpl* returned by MAKE_STATIC_STRING_IMPL should be unique. 707 ASSERT_NE(hello.impl(), hello2.impl()); 708 709 if (testSet == StaticStringImplTestSet::StaticallyAllocatedImpl) { 710 // Test that MAKE_STATIC_STRING_IMPL isn't allocating a StaticStringImpl on the stack. 711 const String& str1 = getNeverDestroyedStringAtStackDepth(10); 712 ASSERT_EQ(strlen("NeverDestroyedString"), str1.length()); 713 ASSERT_TRUE(equal(str1, "NeverDestroyedString")); 714 715 const String& str2 = getNeverDestroyedStringAtStackDepth(20); 716 ASSERT_EQ(strlen("NeverDestroyedString"), str2.length()); 717 ASSERT_TRUE(equal(str2, "NeverDestroyedString")); 718 719 ASSERT_TRUE(equal(str1, str2)); 720 ASSERT_EQ(&str1, &str2); 721 ASSERT_EQ(str1.impl(), str2.impl()); 722 } 723 724 // Test that the StaticStringImpl's hash has already been set. 725 // We're relying on an ASSERT in setHash() to detect that the hash hasn't 726 // already been set. If the hash has already been set, the hash() method 727 // will not call setHash(). 728 ASSERT_EQ(hello.hash(), 0xd17551u); 729 } 730 689 731 TEST(WTF, StaticStringImpl) 690 732 { … … 695 737 String hello2(MAKE_STATIC_STRING_IMPL("hello")); 696 738 697 ASSERT_EQ(strlen("hello"), hello.length()); 698 ASSERT_EQ(strlen("world"), world.length()); 699 ASSERT_EQ(strlen("longer"), longer.length()); 700 ASSERT_EQ(strlen("hello"), hello2.length()); 701 702 ASSERT_TRUE(equal(hello, "hello")); 703 ASSERT_TRUE(equal(world, "world")); 704 ASSERT_TRUE(equal(longer, "longer")); 705 ASSERT_TRUE(equal(hello2, "hello")); 706 707 // Each StaticStringImpl* returned by MAKE_STATIC_STRING_IMPL should be unique. 708 ASSERT_NE(hello.impl(), hello2.impl()); 709 710 // Test that MAKE_STATIC_STRING_IMPL isn't allocating a StaticStringImpl on the stack. 711 const String& str1 = getNeverDestroyedStringAtStackDepth(10); 712 ASSERT_EQ(strlen("NeverDestroyedString"), str1.length()); 713 ASSERT_TRUE(equal(str1, "NeverDestroyedString")); 714 715 const String& str2 = getNeverDestroyedStringAtStackDepth(20); 716 ASSERT_EQ(strlen("NeverDestroyedString"), str2.length()); 717 ASSERT_TRUE(equal(str2, "NeverDestroyedString")); 718 719 ASSERT_TRUE(equal(str1, str2)); 720 ASSERT_EQ(&str1, &str2); 721 ASSERT_EQ(str1.impl(), str2.impl()); 739 doStaticStringImplTests(StaticStringImplTestSet::StaticallyAllocatedImpl, hello, world, longer, hello2); 740 } 741 742 TEST(WTF, DynamicStaticStringImpl) 743 { 744 // Construct using MAKE_STATIC_STRING_IMPL. 745 String hello = StringImpl::createStaticStringImpl("hello", 5); 746 String world = StringImpl::createStaticStringImpl("world", 5); 747 String longer = StringImpl::createStaticStringImpl("longer", 6); 748 String hello2 = StringImpl::createStaticStringImpl("hello", 5); 749 750 doStaticStringImplTests(StaticStringImplTestSet::DynamicallyAllocatedImpl, hello, world, longer, hello2); 722 751 } 723 752
Note:
See TracChangeset
for help on using the changeset viewer.