Title: [199737] trunk/Source/WebKit2
Revision
199737
Author
[email protected]
Date
2016-04-19 12:35:34 -0700 (Tue, 19 Apr 2016)

Log Message

New SPI to export a dictionary of runtime features
https://bugs.webkit.org/show_bug.cgi?id=156645
<rdar://problem/23621666>

Post commit follow-up. Darin gave review comments that
I didn't address in my original commit - I was waiting
on some advice.

* UIProcess/WebPreferences.cpp:
(WebKit::WebPreferences::isEnabledForFeature): Change the macro
to generate a static list of function pointers, rather than
a lot of conditional statements.
(WebKit::WebPreferences::setEnabledForFeature): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (199736 => 199737)


--- trunk/Source/WebKit2/ChangeLog	2016-04-19 19:06:47 UTC (rev 199736)
+++ trunk/Source/WebKit2/ChangeLog	2016-04-19 19:35:34 UTC (rev 199737)
@@ -1,3 +1,19 @@
+2016-04-19  Dean Jackson  <[email protected]>
+
+        New SPI to export a dictionary of runtime features
+        https://bugs.webkit.org/show_bug.cgi?id=156645
+        <rdar://problem/23621666>
+
+        Post commit follow-up. Darin gave review comments that
+        I didn't address in my original commit - I was waiting
+        on some advice.
+
+        * UIProcess/WebPreferences.cpp:
+        (WebKit::WebPreferences::isEnabledForFeature): Change the macro
+        to generate a static list of function pointers, rather than
+        a lot of conditional statements.
+        (WebKit::WebPreferences::setEnabledForFeature): Ditto.
+
 2016-04-19  Chris Dumez  <[email protected]>
 
         Mark more classes as WTF_MAKE_FAST_ALLOCATED

Modified: trunk/Source/WebKit2/UIProcess/WebPreferences.cpp (199736 => 199737)


--- trunk/Source/WebKit2/UIProcess/WebPreferences.cpp	2016-04-19 19:06:47 UTC (rev 199736)
+++ trunk/Source/WebKit2/UIProcess/WebPreferences.cpp	2016-04-19 19:35:34 UTC (rev 199737)
@@ -213,30 +213,54 @@
 
 bool WebPreferences::isEnabledForFeature(const API::ExperimentalFeature& feature) const
 {
-    const String& key = feature.key();
+    struct FeatureGetterMapping {
+        const char* name;
+        bool (WebPreferences::*function) () const;
+    };
 
-#define CALL_EXPERIMENTAL_GETTER(KeyUpper, KeyLower, TypeName, Type, DefaultValue, HumanReadableName, HumanReadableDescription) \
-    if (key == #KeyUpper) \
-        return KeyLower(); \
+#define MAKE_FEATURE_GETTER(KeyUpper, KeyLower, TypeName, Type, DefaultValue, HumanReadableName, HumanReadableDescription) \
+    { #KeyUpper, &WebPreferences::KeyLower }, \
 
-    FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(CALL_EXPERIMENTAL_GETTER)
+    static FeatureGetterMapping getters[] = {
+        FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(MAKE_FEATURE_GETTER)
+    };
 
-#undef CALL_EXPERIMENTAL_GETTER
+#undef MAKE_FEATURE_GETTER
 
+    const String& key = feature.key();
+
+    for (auto& getter : getters) {
+        if (key == getter.name)
+            return (this->*getter.function)();
+    }
+
     return false;
 }
 
 void WebPreferences::setEnabledForFeature(bool value, const API::ExperimentalFeature& feature)
 {
-    const String& key = feature.key();
+    struct FeatureSetterMapping {
+        const char* name;
+        void (WebPreferences::*function) (const bool&);
+    };
 
-#define CALL_EXPERIMENTAL_SETTER(KeyUpper, KeyLower, TypeName, Type, DefaultValue, HumanReadableName, HumanReadableDescription) \
-    if (key == #KeyUpper) \
-        set##KeyUpper(value); \
+#define MAKE_FEATURE_SETTER(KeyUpper, KeyLower, TypeName, Type, DefaultValue, HumanReadableName, HumanReadableDescription) \
+    { #KeyUpper, &WebPreferences::set##KeyUpper }, \
 
-    FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(CALL_EXPERIMENTAL_SETTER)
+    static FeatureSetterMapping setters[] = {
+        FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(MAKE_FEATURE_SETTER)
+    };
+
+#undef MAKE_FEATURE_SETTER
+
+    const String& key = feature.key();
     
-#undef CALL_EXPERIMENTAL_SETTER
+    for (auto& setter : setters) {
+        if (key == setter.name) {
+            (this->*setter.function)(value);
+            return;
+        }
+    }
 }
 
 bool WebPreferences::anyPagesAreUsingPrivateBrowsing()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to