Bug 1465628 part 1 - Use a static table for property preferences. r=emilio
☠☠ backed out by a9e6e98ff2c2 ☠ ☠
authorXidorn Quan <me@upsuper.org>
Thu, 31 May 2018 13:49:25 +1000
changeset 421234 e5ac0c7a9fb49d3d011095283014bae7324361d0
parent 421233 cba6d551e43e6a96eee178b5342225368a4b3130
child 421235 6832baa28e3fa16dc59480f9f475a85e6aca65c3
push id64837
push userxquan@mozilla.com
push dateTue, 05 Jun 2018 00:42:48 +0000
treeherderautoland@04f276eb2f0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1465628
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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_) |       \