WebKit Bugzilla
Attachment 350056 Details for
Bug 189633
: Add count() function to OptionSet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189633-20180918141920.patch (text/plain), 4.48 KB, created by
Woodrow Wang
on 2018-09-18 14:19:20 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Woodrow Wang
Created:
2018-09-18 14:19:20 PDT
Size:
4.48 KB
patch
obsolete
>Subversion Revision: 236144 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index d308be19282a9a310e8404b1044d05cde49dadce..07a64ba2527f9d25b13ec0adb17e328e617fbb7c 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,21 @@ >+2018-09-18 Woodrow Wang <woodrow_wang@apple.com> >+ >+ Add size() function to OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=189633 >+ <rdar://problem/44469944> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add countSetBits() function to MathExtras with specialized templates >+ for 32 bit and 64 bit unsigned integers that use optimized >+ machine instructions. >+ >+ * wtf/MathExtras.h: >+ >+ (WTF::countSetBits): >+ * wtf/OptionSet.h: >+ (WTF::OptionSet::size const): >+ > 2018-09-17 Yusuke Suzuki <utatane.tea@gmail.com> > > [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t >diff --git a/Source/WTF/wtf/MathExtras.h b/Source/WTF/wtf/MathExtras.h >index 512c160c721a576da63ea968793d9b7a2e8f52fa..62e315936f7081cd49166883ba92b6413bc0e05b 100644 >--- a/Source/WTF/wtf/MathExtras.h >+++ b/Source/WTF/wtf/MathExtras.h >@@ -575,6 +575,56 @@ inline unsigned clz64(uint64_t number) > #endif > } > >+template<typename T> constexpr unsigned countSetBits(T number) >+{ >+ unsigned numberOfSetBits = 0; >+ while (number) { >+ number &= number - 1; >+ ++numberOfSetBits; >+ } >+ return numberOfSetBits; >+} >+ >+template<> constexpr unsigned countSetBits(uint64_t number) >+{ >+#if COMPILER(GCC_OR_CLANG) >+ return __builtin_popcountll(number); >+#elif COMPILER(MSVC) >+ >+#if CPU(X86_64) >+ return __popcnt64(number); >+#elif CPU(X86) >+ constexpr uint32_t upper = number >> 32; >+ constexpr uint32_t lower = number & 0xFFFFFFFF; >+ return __popcnt(upper) + __popcnt(lower); >+#endif >+ >+#else >+ unsigned numberOfSetBits = 0; >+ while (number) { >+ number &= number - 1; >+ ++numberOfSetBits; >+ } >+ return numberOfSetBits; >+#endif >+} >+ >+template<> constexpr unsigned countSetBits(uint32_t number) >+{ >+#if COMPILER(GCC_OR_CLANG) >+ return __builtin_popcount(number); >+#elif COMPILER(MSVC) >+ return __popcnt(number); >+#else >+ unsigned numberOfSetBits = 0; >+ while (number) { >+ number &= number - 1; >+ ++numberOfSetBits; >+ } >+ return numberOfSetBits; >+#endif >+} >+ > } // namespace WTF > > using WTF::opaque; >diff --git a/Source/WTF/wtf/OptionSet.h b/Source/WTF/wtf/OptionSet.h >index f18ff2c9ff6f1fd09bef2443f082223f5ab24c7d..65b8bb55fcc0253ab9c03b29a882788edf39487d 100644 >--- a/Source/WTF/wtf/OptionSet.h >+++ b/Source/WTF/wtf/OptionSet.h >@@ -121,6 +121,11 @@ public: > m_storage &= ~optionSet.m_storage; > } > >+ constexpr unsigned size() const >+ { >+ return WTF::countSetBits(m_storage); >+ } >+ > constexpr friend bool operator==(OptionSet lhs, OptionSet rhs) > { > return lhs.m_storage == rhs.m_storage; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 6d2a41b51b5c99556f86f634330ca032692f0ab9..38e5ce8db2a1398ee4e87c7fd57f5e2e5736acb1 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,16 @@ >+2018-09-18 Woodrow Wang <woodrow_wang@apple.com> >+ >+ Add size() function to OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=189633 >+ <rdar://problem/44469944> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add a test for new size() function. >+ >+ * TestWebKitAPI/Tests/WTF/OptionSet.cpp: >+ (TestWebKitAPI::TEST): >+ > 2018-08-31 Woodrow Wang <woodrow_wang@apple.com> > > Add infrastructure to dump resource load statistics >diff --git a/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp b/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp >index 493ec25c06f569cd5439c401f82654cf7b7c2b9b..acbde2d4deae4681a20208831a2885ea49db97ed 100644 >--- a/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp >+++ b/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp >@@ -436,4 +436,23 @@ TEST(WTF_OptionSet, ContainsAll) > EXPECT_FALSE(set.containsAll({ ExampleFlags::A, ExampleFlags::B, ExampleFlags::C })); > } > >+TEST(WTF_OptionSet, Size) >+{ >+ OptionSet<ExampleFlags> set; >+ >+ EXPECT_EQ(set.size(), 0U); >+ set.add(ExampleFlags::A); >+ EXPECT_EQ(set.size(), 1U); >+ set.remove(ExampleFlags::A); >+ set.add(ExampleFlags::B); >+ EXPECT_EQ(set.size(), 1U); >+ set.remove(ExampleFlags::B); >+ set.add(ExampleFlags::E); >+ EXPECT_EQ(set.size(), 1U); >+ set.add(ExampleFlags::A); >+ EXPECT_EQ(set.size(), 2U); >+ set.add(ExampleFlags::C); >+ EXPECT_EQ(set.size(), 3U); >+} >+ > } // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189633
:
349941
|
349946
|
349975
|
349978
|
350056
|
350081
|
350086
|
350134
|
350150
|
350281