From b7cf47462672b88528dfae25213565378d84bd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 19 Jun 2019 05:58:15 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- layout/generic/nsGridContainerFrame.cpp | 10 +++++----- xpcom/ds/nsAtom.h | 7 +++++++ xpcom/ds/nsGkAtoms.h | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index 396f9ded2da5..402f4d65166c 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -944,7 +944,7 @@ class MOZ_STACK_CLASS nsGridContainerFrame::LineNameMap { uint32_t FindNamedLine(nsAtom* aName, int32_t* aNth, uint32_t aFromIndex, const nsTArray& 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); @@ -3385,7 +3385,7 @@ int32_t nsGridContainerFrame::Grid::ResolveLine( 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: must not be zero."); line = int32_t(aFromIndex) + aNth; } else { @@ -3460,7 +3460,7 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper( 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 / span * // span / auto return LinePair(kAutoLine, aStart.mInteger); @@ -3494,7 +3494,7 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper( 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 MOZ_ASSERT(aEnd.mInteger != 0); return LinePair(start, aEnd.mInteger); @@ -3520,7 +3520,7 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper( 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; diff --git a/xpcom/ds/nsAtom.h b/xpcom/ds/nsAtom.h index b149a239e554..9212015d97c6 100644 --- a/xpcom/ds/nsAtom.h +++ b/xpcom/ds/nsAtom.h @@ -75,6 +75,13 @@ class nsAtom { // 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(); diff --git a/xpcom/ds/nsGkAtoms.h b/xpcom/ds/nsGkAtoms.h index 22b4dfd89300..a35460982f60 100644 --- a/xpcom/ds/nsGkAtoms.h +++ b/xpcom/ds/nsGkAtoms.h @@ -180,4 +180,8 @@ class nsGkAtoms { #undef GK_ATOM }; +inline bool nsAtom::IsEmpty() const { + return this == nsGkAtoms::_empty; +} + #endif /* nsGkAtoms_h___ */