From f9e0542b4d14e35129908752b04115c267a0e1c0 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 31 May 2018 13:49:25 +1000 Subject: [PATCH] Bug 1465628 part 1 - Use a static table for property preferences. r=emilio MozReview-Commit-ID: 7tCdZyAlZc0 --HG-- extra : rebase_source : 80ae9bb4199efa3c7948004d329e617b1f14f154 --- layout/style/GenerateCSSPropsGenerated.py | 18 +++++++++++++++-- layout/style/nsCSSProps.cpp | 24 +++++------------------ layout/style/nsCSSProps.h | 6 ++++++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/layout/style/GenerateCSSPropsGenerated.py b/layout/style/GenerateCSSPropsGenerated.py index abd848a925c6..db43dbc285b3 100644 --- a/layout/style/GenerateCSSPropsGenerated.py +++ b/layout/style/GenerateCSSPropsGenerated.py @@ -33,9 +33,9 @@ def generate(output, dataFile): """) - 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 @@ -58,6 +58,20 @@ def generate(output, dataFile): 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: diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index 1326058f50c9..3d594955e6d5 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -123,25 +123,11 @@ nsCSSProps::AddRefTable(void) 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); + } } } } diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h index f8d90b223153..b1f94c7d4e86 100644 --- a/layout/style/nsCSSProps.h +++ b/layout/style/nsCSSProps.h @@ -247,6 +247,12 @@ public: } 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