Title: [266812] trunk
Revision
266812
Author
rn...@webkit.org
Date
2020-09-09 20:40:23 -0700 (Wed, 09 Sep 2020)

Log Message

Simplify OptionSet::set
https://bugs.webkit.org/show_bug.cgi?id=216335

Reviewed by Said Abou-Hallawa.

Source/WTF:

Simplified the implementation of OptionSet::set since we've verified that both clang and gcc
generate comparable code in x86_64 and clang does the same for arm64.

* wtf/OptionSet.h:
(WTF::OptionSet::set):

Tools:

Added a unit test for OptionSet::set.

* TestWebKitAPI/Tests/WTF/OptionSet.cpp:
(WTF_OptionSet.Set):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (266811 => 266812)


--- trunk/Source/WTF/ChangeLog	2020-09-10 03:15:42 UTC (rev 266811)
+++ trunk/Source/WTF/ChangeLog	2020-09-10 03:40:23 UTC (rev 266812)
@@ -1,3 +1,16 @@
+2020-09-09  Ryosuke Niwa  <rn...@webkit.org>
+
+        Simplify OptionSet::set
+        https://bugs.webkit.org/show_bug.cgi?id=216335
+
+        Reviewed by Said Abou-Hallawa.
+
+        Simplified the implementation of OptionSet::set since we've verified that both clang and gcc
+        generate comparable code in x86_64 and clang does the same for arm64.
+
+        * wtf/OptionSet.h:
+        (WTF::OptionSet::set):
+
 2020-09-09  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Text copied and pasted from Mac Catalyst apps appears larger than expected

Modified: trunk/Source/WTF/wtf/OptionSet.h (266811 => 266812)


--- trunk/Source/WTF/wtf/OptionSet.h	2020-09-10 03:15:42 UTC (rev 266811)
+++ trunk/Source/WTF/wtf/OptionSet.h	2020-09-10 03:40:23 UTC (rev 266812)
@@ -195,7 +195,10 @@
 
     constexpr void set(OptionSet optionSet, bool value)
     {
-        m_storage = (m_storage & ~optionSet.m_storage) | (-static_cast<StorageType>(value) & optionSet.m_storage);
+        if (value)
+            add(optionSet);
+        else
+            remove(optionSet);
     }
 
     constexpr bool hasExactlyOneBitSet() const

Modified: trunk/Tools/ChangeLog (266811 => 266812)


--- trunk/Tools/ChangeLog	2020-09-10 03:15:42 UTC (rev 266811)
+++ trunk/Tools/ChangeLog	2020-09-10 03:40:23 UTC (rev 266812)
@@ -1,3 +1,15 @@
+2020-09-09  Ryosuke Niwa  <rn...@webkit.org>
+
+        Simplify OptionSet::set
+        https://bugs.webkit.org/show_bug.cgi?id=216335
+
+        Reviewed by Said Abou-Hallawa.
+
+        Added a unit test for OptionSet::set.
+
+        * TestWebKitAPI/Tests/WTF/OptionSet.cpp:
+        (WTF_OptionSet.Set):
+
 2020-09-09  Fujii Hironori  <hironori.fu...@sony.com>
 
         Add Visual Studio debugger custom views for NeverDestroyed, LazyNeverDestroyed, VectorBufferBase, Optional, and StringView

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp (266811 => 266812)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp	2020-09-10 03:15:42 UTC (rev 266811)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp	2020-09-10 03:40:23 UTC (rev 266812)
@@ -123,6 +123,31 @@
     EXPECT_FALSE(set.contains(ExampleFlags::C));
 }
 
+TEST(WTF_OptionSet, Set)
+{
+    OptionSet<ExampleFlags> set;
+
+    set.set(ExampleFlags::A, true);
+    EXPECT_TRUE(set.contains(ExampleFlags::A));
+    EXPECT_FALSE(set.contains(ExampleFlags::B));
+    EXPECT_FALSE(set.contains(ExampleFlags::C));
+
+    set.set({ ExampleFlags::B, ExampleFlags::C }, true);
+    EXPECT_TRUE(set.contains(ExampleFlags::A));
+    EXPECT_TRUE(set.contains(ExampleFlags::B));
+    EXPECT_TRUE(set.contains(ExampleFlags::C));
+
+    set.set(ExampleFlags::B, false);
+    EXPECT_TRUE(set.contains(ExampleFlags::A));
+    EXPECT_FALSE(set.contains(ExampleFlags::B));
+    EXPECT_TRUE(set.contains(ExampleFlags::C));
+
+    set.set({ ExampleFlags::A, ExampleFlags::C }, false);
+    EXPECT_FALSE(set.contains(ExampleFlags::A));
+    EXPECT_FALSE(set.contains(ExampleFlags::B));
+    EXPECT_FALSE(set.contains(ExampleFlags::C));
+}
+
 TEST(WTF_OptionSet, ContainsTwoFlags)
 {
     OptionSet<ExampleFlags> set { ExampleFlags::A, ExampleFlags::B };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to