gecko-dev/layout/style/nsCSSAnonBoxes.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.2 KiB
C
Raw Normal View History

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
2012-05-21 11:12:37 +00:00
/* 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/. */
/* atom list for CSS anonymous boxes */
#ifndef nsCSSAnonBoxes_h___
#define nsCSSAnonBoxes_h___
#include "nsAtom.h"
#include "nsGkAtoms.h"
#include "mozilla/PseudoStyleType.h"
Bug 1411469 - Statically allocate static atoms. r=froydnj Currently static atoms are stored on the heap, but their char buffers are stored in read-only static memory. This patch changes the representation of nsStaticAtom (thus making it a non-trivial subclass of nsAtom). Instead of a pointer to the string, it now has an mStringOffset field which is a 32-bit offset to the string. (This requires placement of the string and the atom within the same object so that the offset is known to be small. The docs and macros in nsStaticAtom.h handle that.) Static and dynamic atoms now store their chars in different ways: nsStaticAtom stores them inline, nsDynamicAtom has a pointer to separate storage. So `mString` and GetStringBuffer() move from nsAtom to nsDynamicAtom. The change to static atoms means they can be made constexpr and stored in read-only memory instead of on the heap. On 64-bit this reduces the per-process overhead by 16 bytes; on 32-bit the saving is 12 bytes. (Further reductions will be possible in follow-up patches.) The increased use of constexpr required multiple workarounds for MSVC. - Multiple uses of MOZ_{PUSH,POP}_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING to disable warnings about (well-defined!) overflow of unsigned integer arithmetic. - The use of -Zc:externConstexpr on all files defining static atoms, to make MSVC follow the C++ standard(!) and let constexpr variables have external linkage. - The use of -constexpr:steps300000 to increase the number of operations allowed in a constexpr value, in order to handle gGkAtoms, which requires hashing ~2,500 atom strings. The patch also changes how HTML5 atoms are handled. They are now treated as dynamic atoms, i.e. we have "dynamic normal" atoms and "dynamic HTML5 atoms", and "dynamic atoms" covers both cases, and both are represented via nsDynamicAtom. The main difference between the two kinds is that dynamic HTML5 atoms still aren't allowed to be used in various operations, most notably AddRef()/Release(). All this also required moving nsDynamicAtom into the header file. There is a slight performance cost to all these changes: now that nsStaticAtom and nsDynamicAtom store their chars in different ways, a conditional branch is required in the following functions: Equals(), GetUTF16String(), WeakAtom::as_slice(). Finally, in about:memory the "explicit/atoms/static/atom-objects" value is no longer needed, because that memory is static instead of heap-allocated. MozReview-Commit-ID: 4AxPv05ngZy
2018-03-08 01:59:11 +00:00
class nsCSSAnonBoxes {
using PseudoStyleType = mozilla::PseudoStyleType;
using PseudoStyle = mozilla::PseudoStyle;
public:
#ifdef MOZ_XUL
static bool IsTreePseudoElement(nsAtom* aPseudo);
#endif
static bool IsNonElement(PseudoStyleType aPseudo) {
return aPseudo == PseudoStyleType::mozText ||
aPseudo == PseudoStyleType::oofPlaceholder ||
aPseudo == PseudoStyleType::firstLetterContinuation;
}
1998-12-11 02:51:05 +00:00
enum class NonInheriting : uint8_t {
#define CSS_ANON_BOX(_name, _value) /* nothing */
#define CSS_NON_INHERITING_ANON_BOX(_name, _value) _name,
#include "nsCSSAnonBoxList.h"
#undef CSS_NON_INHERITING_ANON_BOX
#undef CSS_ANON_BOX
_Count
};
// Get the NonInheriting type for a given pseudo tag. The pseudo tag must
// test true for IsNonInheritingAnonBox.
static NonInheriting NonInheritingTypeForPseudoType(PseudoStyleType aType) {
MOZ_ASSERT(PseudoStyle::IsNonInheritingAnonBox(aType));
static_assert(sizeof(PseudoStyleType) == sizeof(uint8_t), "");
return static_cast<NonInheriting>(
static_cast<uint8_t>(aType) -
static_cast<uint8_t>(PseudoStyleType::NonInheritingAnonBoxesStart));
}
#ifdef DEBUG
static nsStaticAtom* GetAtomBase();
static void AssertAtoms();
#endif
// Alias nsCSSAnonBoxes::foo() to nsGkAtoms::AnonBox_foo.
#define CSS_ANON_BOX(name_, value_) \
static nsCSSAnonBoxPseudoStaticAtom* name_() { \
return const_cast<nsCSSAnonBoxPseudoStaticAtom*>( \
static_cast<const nsCSSAnonBoxPseudoStaticAtom*>( \
nsGkAtoms::AnonBox_##name_)); \
}
#include "nsCSSAnonBoxList.h"
#undef CSS_ANON_BOX
};
1998-12-11 02:51:05 +00:00
#endif /* nsCSSAnonBoxes_h___ */