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
This commit is contained in:
Emilio Cobos Álvarez 2019-06-19 05:58:15 +00:00
Родитель 6ed8680108
Коммит b7cf474626
3 изменённых файлов: 16 добавлений и 5 удалений

Просмотреть файл

@ -944,7 +944,7 @@ class MOZ_STACK_CLASS nsGridContainerFrame::LineNameMap {
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);
@ -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: <integer> 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 <integer> / span *
// span <integer> / 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 <integer>
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;

Просмотреть файл

@ -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();

Просмотреть файл

@ -180,4 +180,8 @@ class nsGkAtoms {
#undef GK_ATOM
};
inline bool nsAtom::IsEmpty() const {
return this == nsGkAtoms::_empty;
}
#endif /* nsGkAtoms_h___ */