Bug 1575713 - Use atoms for font-feature-values. r=boris
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 22 Aug 2019 00:24:44 +0000
changeset 489352 8ca157711117d3af9716bc7f3f19125b8957def5
parent 489351 8beaed1849e8b2691eb968309280e8055476c027
child 489353 c44b510774123df58588ef9b41c4ec0bd204b473
push id93282
push userealvarez@mozilla.com
push dateThu, 22 Aug 2019 00:25:44 +0000
treeherderautoland@c44b51077412 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersboris
bugs1575713
milestone70.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 1575713 - Use atoms for font-feature-values. r=boris Differential Revision: https://phabricator.services.mozilla.com/D42984
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFontFeatures.cpp
gfx/thebes/gfxFontFeatures.h
layout/style/GeckoBindings.cpp
layout/style/GeckoBindings.h
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -344,17 +344,17 @@ static void LookupAlternateValues(gfxFon
 
   gfxFontFeature feature;
   if (aAlternates.IsCharacterVariant()) {
     for (auto& ident : aAlternates.AsCharacterVariant().AsSpan()) {
       AutoTArray<uint32_t, 4> values;
       // FIXME(emilio): Use atoms directly.
       aFeatureLookup.GetFontFeatureValuesFor(
           aFamily, NS_FONT_VARIANT_ALTERNATES_CHARACTER_VARIANT,
-          nsDependentAtomString(ident.AsAtom()), values);
+          ident.AsAtom(), values);
       // nothing defined, skip
       if (values.IsEmpty()) {
         continue;
       }
       NS_ASSERTION(values.Length() <= 2,
                    "too many values allowed for character-variant");
       // character-variant(12 3) ==> 'cv12' = 3
       uint32_t nn = values[0];
@@ -370,17 +370,17 @@ static void LookupAlternateValues(gfxFon
   }
 
   if (aAlternates.IsStyleset()) {
     for (auto& ident : aAlternates.AsStyleset().AsSpan()) {
       AutoTArray<uint32_t, 4> values;
       // FIXME(emilio): Use atoms directly.
       aFeatureLookup.GetFontFeatureValuesFor(
           aFamily, NS_FONT_VARIANT_ALTERNATES_STYLESET,
-          nsDependentAtomString(ident.AsAtom()), values);
+          ident.AsAtom(), values);
 
       // styleset(1 2 7) ==> 'ss01' = 1, 'ss02' = 1, 'ss07' = 1
       feature.mValue = 1;
       for (uint32_t nn : values) {
         if (nn == 0 || nn > MAX_SSXX_VALUE) {
           continue;
         }
         feature.mTag = HB_TAG('s', 's', ('0' + nn / 10), ('0' + nn % 10));
@@ -410,18 +410,17 @@ static void LookupAlternateValues(gfxFon
       name = aAlternates.AsAnnotation().AsAtom();
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Unknown font-variant-alternates value!");
       return;
   }
 
   AutoTArray<uint32_t, 4> values;
-  aFeatureLookup.GetFontFeatureValuesFor(aFamily, constant,
-                                         nsDependentAtomString(name), values);
+  aFeatureLookup.GetFontFeatureValuesFor(aFamily, constant, name, values);
   if (values.IsEmpty()) {
     return;
   }
   MOZ_ASSERT(values.Length() == 1,
              "too many values for font-specific font-variant-alternates");
 
   feature.mValue = values[0];
   switch (aAlternates.tag) {
--- a/gfx/thebes/gfxFontFeatures.cpp
+++ b/gfx/thebes/gfxFontFeatures.cpp
@@ -1,24 +1,25 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxFontFeatures.h"
+#include "nsAtom.h"
 #include "nsUnicharUtils.h"
 #include "nsHashKeys.h"
 
 using namespace mozilla;
 
 gfxFontFeatureValueSet::gfxFontFeatureValueSet() : mFontFeatureValues(8) {}
 
 bool gfxFontFeatureValueSet::GetFontFeatureValuesFor(
     const nsACString& aFamily, uint32_t aVariantProperty,
-    const nsAString& aName, nsTArray<uint32_t>& aValues) {
+    nsAtom* aName, nsTArray<uint32_t>& aValues) {
   nsAutoCString family(aFamily);
   ToLowerCase(family);
   FeatureValueHashKey key(family, aVariantProperty, aName);
 
   aValues.Clear();
   FeatureValueHashEntry* entry = mFontFeatureValues.GetEntry(key);
   if (entry) {
     NS_ASSERTION(entry->mValues.Length() > 0,
@@ -26,26 +27,27 @@ bool gfxFontFeatureValueSet::GetFontFeat
     aValues.AppendElements(entry->mValues);
     return true;
   }
 
   return false;
 }
 
 nsTArray<uint32_t>* gfxFontFeatureValueSet::AppendFeatureValueHashEntry(
-    const nsACString& aFamily, const nsAString& aName, uint32_t aAlternate) {
+    const nsACString& aFamily, nsAtom* aName, uint32_t aAlternate) {
   FeatureValueHashKey key(aFamily, aAlternate, aName);
   FeatureValueHashEntry* entry = mFontFeatureValues.PutEntry(key);
   entry->mKey = key;
   return &entry->mValues;
 }
 
 bool gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals(
     const KeyTypePointer aKey) const {
   return aKey->mPropVal == mKey.mPropVal &&
-         aKey->mFamily.Equals(mKey.mFamily) && aKey->mName.Equals(mKey.mName);
+         aKey->mName == mKey.mName &&
+         aKey->mFamily.Equals(mKey.mFamily);
 }
 
 PLDHashNumber gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey(
     const KeyTypePointer aKey) {
-  return HashString(aKey->mFamily) + HashString(aKey->mName) +
+  return HashString(aKey->mFamily) + aKey->mName->hash() +
          aKey->mPropVal * uint32_t(0xdeadbeef);
 }
--- a/gfx/thebes/gfxFontFeatures.h
+++ b/gfx/thebes/gfxFontFeatures.h
@@ -22,16 +22,18 @@ struct gfxFontFeature {
 inline bool operator<(const gfxFontFeature& a, const gfxFontFeature& b) {
   return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
 }
 
 inline bool operator==(const gfxFontFeature& a, const gfxFontFeature& b) {
   return (a.mTag == b.mTag) && (a.mValue == b.mValue);
 }
 
+class nsAtom;
+
 class gfxFontFeatureValueSet final {
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFeatureValueSet)
 
   gfxFontFeatureValueSet();
 
   struct ValueList {
     ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors)
@@ -43,37 +45,37 @@ class gfxFontFeatureValueSet final {
   struct FeatureValues {
     uint32_t alternate;
     nsTArray<ValueList> valuelist;
   };
 
   // returns true if found, false otherwise
   bool GetFontFeatureValuesFor(const nsACString& aFamily,
                                uint32_t aVariantProperty,
-                               const nsAString& aName,
+                               nsAtom* aName,
                                nsTArray<uint32_t>& aValues);
 
   // Appends a new hash entry with given key values and returns a pointer to
   // mValues array to fill. This should be filled first.
   nsTArray<uint32_t>* AppendFeatureValueHashEntry(const nsACString& aFamily,
-                                                  const nsAString& aName,
+                                                  nsAtom* aName,
                                                   uint32_t aAlternate);
 
  private:
   // Private destructor, to discourage deletion outside of Release():
   ~gfxFontFeatureValueSet() {}
 
   struct FeatureValueHashKey {
     nsCString mFamily;
     uint32_t mPropVal;
-    nsString mName;
+    RefPtr<nsAtom> mName;
 
     FeatureValueHashKey() : mPropVal(0) {}
     FeatureValueHashKey(const nsACString& aFamily, uint32_t aPropVal,
-                        const nsAString& aName)
+                        nsAtom* aName)
         : mFamily(aFamily), mPropVal(aPropVal), mName(aName) {}
     FeatureValueHashKey(const FeatureValueHashKey& aKey)
         : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName) {}
   };
 
   class FeatureValueHashEntry : public PLDHashEntryHdr {
    public:
     typedef const FeatureValueHashKey& KeyType;
--- a/layout/style/GeckoBindings.cpp
+++ b/layout/style/GeckoBindings.cpp
@@ -1023,24 +1023,22 @@ StyleGenericFontFamily Gecko_nsStyleFont
       ThreadSafeGetDefaultFontHelper(*aDoc, aLanguage, aGenericId);
   return defaultFont->fontlist.GetDefaultFontType();
 }
 
 gfxFontFeatureValueSet* Gecko_ConstructFontFeatureValueSet() {
   return new gfxFontFeatureValueSet();
 }
 
-nsTArray<unsigned int>* Gecko_AppendFeatureValueHashEntry(
+nsTArray<uint32_t>* Gecko_AppendFeatureValueHashEntry(
     gfxFontFeatureValueSet* aFontFeatureValues, nsAtom* aFamily,
     uint32_t aAlternate, nsAtom* aName) {
   MOZ_ASSERT(NS_IsMainThread());
-  static_assert(sizeof(unsigned int) == sizeof(uint32_t),
-                "sizeof unsigned int and uint32_t must be the same");
   return aFontFeatureValues->AppendFeatureValueHashEntry(
-      nsAtomCString(aFamily), nsDependentAtomString(aName), aAlternate);
+      nsAtomCString(aFamily), aName, aAlternate);
 }
 
 float Gecko_FontStretch_ToFloat(FontStretch aStretch) {
   // Servo represents percentages with 1. being 100%.
   return aStretch.Percentage() / 100.0f;
 }
 
 void Gecko_FontStretch_SetFloat(FontStretch* aStretch, float aFloat) {
--- a/layout/style/GeckoBindings.h
+++ b/layout/style/GeckoBindings.h
@@ -290,17 +290,17 @@ void Gecko_nsFont_InitSystem(nsFont* dst
                              const nsStyleFont* font,
                              const mozilla::dom::Document*);
 
 void Gecko_nsFont_Destroy(nsFont* dst);
 
 // The gfxFontFeatureValueSet returned from this function has zero reference.
 gfxFontFeatureValueSet* Gecko_ConstructFontFeatureValueSet();
 
-nsTArray<unsigned int>* Gecko_AppendFeatureValueHashEntry(
+nsTArray<uint32_t>* Gecko_AppendFeatureValueHashEntry(
     gfxFontFeatureValueSet* value_set, nsAtom* family, uint32_t alternate,
     nsAtom* name);
 
 // Font variant alternates
 void Gecko_ClearAlternateValues(nsFont* font, size_t length);
 
 void Gecko_AppendAlternateValues(nsFont* font, uint32_t alternate_name,
                                  nsAtom* atom);