Bug 1465628 part 1 - Use a static table for property preferences. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Thu, 31 May 2018 13:49:25 +1000
changeset 803955 a965254b2b3b54391934111fe8cb41a96c5cbc22
parent 803954 d300243a8d3b85e1b1b26a0136b0e72f86fffd65
child 803956 8b16a81b7d10dda5c84971bd61ad48d04ad9400c
push id112243
push userxquan@mozilla.com
push dateTue, 05 Jun 2018 04:32:37 +0000
reviewersemilio
bugs1465628
milestone62.0a1
Bug 1465628 part 1 - Use a static table for property preferences. r?emilio MozReview-Commit-ID: 7tCdZyAlZc0
layout/style/GenerateCSSPropsGenerated.py
layout/style/nsCSSProps.cpp
layout/style/nsCSSProps.h
--- a/layout/style/GenerateCSSPropsGenerated.py
+++ b/layout/style/GenerateCSSPropsGenerated.py
@@ -28,19 +28,19 @@ class PropertyWrapper(object):
 def generate(output, dataFile):
     output.write("""/* THIS IS AN AUTOGENERATED FILE.  DO NOT EDIT */
 
 /* processed file that defines CSS property tables that can't be generated
    with the pre-processor, designed to be #included in nsCSSProps.cpp */
 
 """)
 
-    properties = runpy.run_path(dataFile)["data"]
+    raw_properties = runpy.run_path(dataFile)["data"]
     properties = [PropertyWrapper(i, p)
-                  for i, p in enumerate(properties)
+                  for i, p in enumerate(raw_properties)
                   if p.type() != "alias"]
 
     # Generate kIDLNameTable
     output.write("const char* const nsCSSProps::"
                  "kIDLNameTable[eCSSProperty_COUNT] = {\n")
     for p in properties:
         if p.idlname is None:
             output.write("  nullptr,  // {}\n".format(p.name))
@@ -53,16 +53,30 @@ def generate(output, dataFile):
     ps = [(p, position) for position, p in enumerate(ps)]
     ps.sort(key=lambda (p, position): p.index)
     output.write("const int32_t nsCSSProps::"
                  "kIDLNameSortPositionTable[eCSSProperty_COUNT] = {\n")
     for (p, position) in ps:
         output.write("  {},\n".format(position))
     output.write("};\n\n")
 
+    # Generate preferences table
+    output.write("const nsCSSProps::PropertyPref "
+                 "nsCSSProps::kPropertyPrefTable[] = {\n")
+    for p in raw_properties:
+        if not p.pref:
+            continue
+        if p.type() != "alias":
+            prop_id = "eCSSProperty_" + p.id
+        else:
+            prop_id = "eCSSPropertyAlias_" + p.alias_id
+        output.write("  {{ {}, \"{}\" }},\n".format(prop_id, p.pref))
+    output.write("  { eCSSProperty_UNKNOWN, nullptr },\n")
+    output.write("};\n\n")
+
     # Generate shorthand subprop tables
     names = []
     for p in properties:
         if p.type() != "shorthand":
             continue
         name = "g{}SubpropTable".format(p.method)
         names.append(name)
         output.write("static const nsCSSPropertyID {}[] = {{\n".format(name))
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -118,35 +118,21 @@ nsCSSProps::AddRefTable(void)
       if (kIDLNameTable[p]) {
         gPropertyIDLNameTable->Put(nsDependentCString(kIDLNameTable[p]), p);
       }
     }
 
     static bool prefObserversInited = false;
     if (!prefObserversInited) {
       prefObserversInited = true;
-
-      #define OBSERVE_PROP(pref_, id_)                                        \
-        if (pref_[0]) {                                                       \
-          Preferences::AddBoolVarCache(&gPropertyEnabled[id_],                \
-                                       pref_);                                \
-        }
-
-      #define CSS_PROP_LONGHAND(name_, id_, method_, flags_, pref_) \
-        OBSERVE_PROP(pref_, eCSSProperty_##id_)
-      #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \
-        OBSERVE_PROP(pref_, eCSSProperty_##id_)
-      #define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, pref_) \
-        OBSERVE_PROP(pref_, eCSSPropertyAlias_##aliasid_)
-      #include "mozilla/ServoCSSPropList.h"
-      #undef CSS_PROP_ALIAS
-      #undef CSS_PROP_SHORTHAND
-      #undef CSS_PROP_LONGHAND
-
-      #undef OBSERVE_PROP
+      for (const PropertyPref* pref = kPropertyPrefTable;
+           pref->mPropID != eCSSProperty_UNKNOWN; pref++) {
+        bool* enabled = &gPropertyEnabled[pref->mPropID];
+        Preferences::AddBoolVarCache(enabled, pref->mPref);
+      }
     }
   }
 }
 
 #undef  DEBUG_SHORTHANDS_CONTAINING
 
 void
 nsCSSProps::ReleaseTable(void)
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -242,16 +242,22 @@ public:
         PropHasFlags(aProperty, Flags::EnabledInChrome))
     {
       return true;
     }
     return false;
   }
 
 public:
+  struct PropertyPref
+  {
+    nsCSSPropertyID mPropID;
+    const char* mPref;
+  };
+  static const PropertyPref kPropertyPrefTable[];
 
 // Storing the enabledstate_ value in an nsCSSPropertyID variable is a small hack
 // to avoid needing a separate variable declaration for its real type
 // (CSSEnabledState), which would then require using a block and
 // therefore a pair of macros by consumers for the start and end of the loop.
 #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(it_, prop_, enabledstate_)   \
   for (const nsCSSPropertyID *it_ = nsCSSProps::SubpropertyEntryFor(prop_), \
                             es_ = (nsCSSPropertyID)((enabledstate_) |       \