Bug 1559546 - Introduce nsAtom::IsEmpty. r=njn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 19 Jun 2019 05:58:15 +0000
changeset 479183 8567a308ac7a8e2087903aedd1d92032c9c7eb60
parent 479182 acf98e967abe248d16574757806f3a0f68579d3f
child 479184 046dd0da3b8e606ae33895248cd41e4ef03a4fcc
push id36173
push userrgurzau@mozilla.com
push dateWed, 19 Jun 2019 15:50:11 +0000
treeherdermozilla-central@10e3ed789e2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1559546
milestone69.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 1559546 - Introduce nsAtom::IsEmpty. r=njn Both for symmetry with other string APIs, and also to prevent footguns (since I debugged for a while a typo where I wrote nsGkAtoms::empty rather than nsGkAtoms::_empty). We could use null here, but that will not be possible in the future when I use the rust representation of more grid data structures (at least without increasing memory usage). So I think I'll keep using ::_empty as a signaling value for "no grid identifier". Differential Revision: https://phabricator.services.mozilla.com/D35120
layout/generic/nsGridContainerFrame.cpp
xpcom/ds/nsAtom.h
xpcom/ds/nsGkAtoms.h
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -939,17 +939,17 @@ class MOZ_STACK_CLASS nsGridContainerFra
    * aFromIndex is ExplicitGridEnd + 1 (which is the line "before" the last
    * line when we're searching in reverse).  For "span A 2", aNth is 2 when
    * used on a grid-[row|column]-end property and -2 for a *-start property,
    * and aFromIndex is the line (which we should skip) on the opposite property.
    */
   uint32_t FindNamedLine(nsAtom* aName, int32_t* aNth, uint32_t aFromIndex,
                          const nsTArray<uint32_t>& aImplicitLines) const {
     MOZ_ASSERT(aName);
-    MOZ_ASSERT(aName != nsGkAtoms::_empty);
+    MOZ_ASSERT(!aName->IsEmpty());
     MOZ_ASSERT(aNth && *aNth != 0);
     if (*aNth > 0) {
       return FindLine(aName, aNth, aFromIndex, aImplicitLines);
     }
     int32_t nth = -*aNth;
     int32_t line = RFindLine(aName, &nth, aFromIndex, aImplicitLines);
     *aNth = -nth;
     return line;
@@ -3380,17 +3380,17 @@ void nsGridContainerFrame::InitImplicitN
 }
 
 int32_t nsGridContainerFrame::Grid::ResolveLine(
     const nsStyleGridLine& aLine, int32_t aNth, uint32_t aFromIndex,
     const LineNameMap& aNameMap, LogicalSide aSide, uint32_t aExplicitGridEnd,
     const nsStylePosition* aStyle) {
   MOZ_ASSERT(!aLine.IsAuto());
   int32_t line = 0;
-  if (aLine.mLineName == nsGkAtoms::_empty) {
+  if (aLine.mLineName->IsEmpty()) {
     MOZ_ASSERT(aNth != 0, "css-grid 9.2: <integer> must not be zero.");
     line = int32_t(aFromIndex) + aNth;
   } else {
     if (aNth == 0) {
       // <integer> was omitted; treat it as 1.
       aNth = 1;
     }
     bool isNameOnly = !aLine.mHasSpan && aLine.mInteger == 0;
@@ -3455,17 +3455,17 @@ nsGridContainerFrame::Grid::ResolveLineR
     const LineNameMap& aNameMap, LogicalAxis aAxis, uint32_t aExplicitGridEnd,
     const nsStylePosition* aStyle) {
   MOZ_ASSERT(int32_t(nsGridContainerFrame::kAutoLine) >
              nsStyleGridLine::kMaxLine);
 
   if (aStart.mHasSpan) {
     if (aEnd.mHasSpan || aEnd.IsAuto()) {
       // http://dev.w3.org/csswg/css-grid/#grid-placement-errors
-      if (aStart.mLineName == nsGkAtoms::_empty) {
+      if (aStart.mLineName->IsEmpty()) {
         // span <integer> / span *
         // span <integer> / auto
         return LinePair(kAutoLine, aStart.mInteger);
       }
       // span <custom-ident> / span *
       // span <custom-ident> / auto
       return LinePair(kAutoLine, 1);  // XXX subgrid explicit size instead of 1?
     }
@@ -3489,17 +3489,17 @@ nsGridContainerFrame::Grid::ResolveLineR
 
   int32_t start = kAutoLine;
   if (aStart.IsAuto()) {
     if (aEnd.IsAuto()) {
       // auto / auto
       return LinePair(start, 1);  // XXX subgrid explicit size instead of 1?
     }
     if (aEnd.mHasSpan) {
-      if (aEnd.mLineName == nsGkAtoms::_empty) {
+      if (aEnd.mLineName->IsEmpty()) {
         // auto / span <integer>
         MOZ_ASSERT(aEnd.mInteger != 0);
         return LinePair(start, aEnd.mInteger);
       }
       // http://dev.w3.org/csswg/css-grid/#grid-placement-errors
       // auto / span <custom-ident>
       return LinePair(start, 1);  // XXX subgrid explicit size instead of 1?
     }
@@ -3515,17 +3515,17 @@ nsGridContainerFrame::Grid::ResolveLineR
       return LinePair(start, start);
     }
   }
 
   uint32_t from;
   int32_t nth = aEnd.mInteger == 0 ? 1 : aEnd.mInteger;
   if (aEnd.mHasSpan) {
     if (MOZ_UNLIKELY(start < 0)) {
-      if (aEnd.mLineName == nsGkAtoms::_empty) {
+      if (aEnd.mLineName->IsEmpty()) {
         return LinePair(start, start + nth);
       }
       from = 0;
     } else {
       if (start >= int32_t(aExplicitGridEnd)) {
         // The start is at or after the last explicit line, thus all lines
         // after it match <custom-ident> since they're implicit.
         return LinePair(start, std::min(start + nth, aNameMap.mClampMaxLine));
--- a/xpcom/ds/nsAtom.h
+++ b/xpcom/ds/nsAtom.h
@@ -70,16 +70,23 @@ class nsAtom {
   // BloomFilter requires elements to implement a function called hash().
   //
   uint32_t hash() const { return mHash; }
 
   // This function returns true if ToLowercaseASCII would return the string
   // unchanged.
   bool IsAsciiLowercase() const { return mIsAsciiLowercase; }
 
+  // This function returns true if this is the empty atom. This is exactly
+  // equivalent to `this == nsGkAtoms::_empty`, but it's a bit less foot-gunny,
+  // since we also have `nsGkAtoms::empty`.
+  //
+  // Defined in nsGkAtoms.h
+  inline bool IsEmpty() const;
+
   // We can't use NS_INLINE_DECL_THREADSAFE_REFCOUNTING because the refcounting
   // of this type is special.
   inline MozExternalRefCountType AddRef();
   inline MozExternalRefCountType Release();
 
   typedef mozilla::TrueType HasThreadSafeRefCnt;
 
  protected:
--- a/xpcom/ds/nsGkAtoms.h
+++ b/xpcom/ds/nsGkAtoms.h
@@ -175,9 +175,13 @@ class nsGkAtoms {
 #define GK_ATOM(name_, value_, hash_, is_ascii_lower_, type_, atom_type_) \
   static constexpr nsStaticAtom* name_ = const_cast<nsStaticAtom*>(       \
       &mozilla::detail::gGkAtoms.mAtoms[static_cast<size_t>(              \
           mozilla::detail::GkAtoms::Atoms::name_)]);
 #include "nsGkAtomList.h"
 #undef GK_ATOM
 };
 
+inline bool nsAtom::IsEmpty() const {
+  return this == nsGkAtoms::_empty;
+}
+
 #endif /* nsGkAtoms_h___ */