Bug 1446865 - Move nsAtomListUtils. r=froydnj
It seems silly to have a tiny utils class with a single function in its own
module. This patch moves it into nsStaticAtom.h/nsAtomTable.cpp. It also
renames nsAtomListUtils as nsStaticAtomUtils. Finally, it uses templates to
remove the need for the `aCount` parameter at callsites.
MozReview-Commit-ID: DvJVoZFv89c
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -39,17 +39,16 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'dom'
EXPORTS += [
'AutocompleteFieldList.h',
'Crypto.h',
'HTMLSplitOnSpacesTokenizer.h',
'IframeSandboxKeywordList.h',
'mozAutoDocUpdate.h',
- 'nsAtomListUtils.h',
'nsAttrAndChildArray.h',
'nsAttrName.h',
'nsAttrValue.h',
'nsAttrValueInlines.h',
'nsCaseTreatment.h',
'nsChildContentList.h',
'nsContentCID.h',
'nsContentCreatorFunctions.h',
@@ -265,17 +264,16 @@ UNIFIED_SOURCES += [
'ImageEncoder.cpp',
'ImageTracker.cpp',
'IntlUtils.cpp',
'Link.cpp',
'Location.cpp',
'Navigator.cpp',
'NodeInfo.cpp',
'NodeIterator.cpp',
- 'nsAtomListUtils.cpp',
'nsAttrAndChildArray.cpp',
'nsAttrValue.cpp',
'nsAttrValueOrString.cpp',
'nsCCUncollectableMarker.cpp',
'nsContentAreaDragDrop.cpp',
'nsContentIterator.cpp',
'nsContentList.cpp',
'nsContentPermissionHelper.cpp',
deleted file mode 100644
--- a/dom/base/nsAtomListUtils.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-/*
- * Static helper class for implementing atom lists.
- */
-
-#include "nsAtomListUtils.h"
-#include "nsAtom.h"
-#include "nsStaticAtom.h"
-
-/* static */ bool
-nsAtomListUtils::IsMember(nsAtom *aAtom,
- const nsStaticAtomSetup* aSetup,
- uint32_t aCount)
-{
- for (const nsStaticAtomSetup *setup = aSetup, *setup_end = aSetup + aCount;
- setup != setup_end; ++setup) {
- if (aAtom == *(setup->mAtomp))
- return true;
- }
- return false;
-}
deleted file mode 100644
--- a/dom/base/nsAtomListUtils.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-/*
- * Static helper class for implementing atom lists.
- */
-
-#ifndef nsAtomListUtils_h__
-#define nsAtomListUtils_h__
-
-#include <stdint.h>
-
-class nsAtom;
-struct nsStaticAtomSetup;
-
-class nsAtomListUtils {
-public:
- static bool IsMember(nsAtom *aAtom,
- const nsStaticAtomSetup* aSetup,
- uint32_t aCount);
-};
-
-#endif /* !defined(nsAtomListUtils_h__) */
--- a/dom/base/nsContentCreatorFunctions.h
+++ b/dom/base/nsContentCreatorFunctions.h
@@ -11,16 +11,17 @@
#include "nsCOMPtr.h"
#include "mozilla/dom/FromParser.h"
/**
* Functions to create content, to be used only inside Gecko
* (mozilla/content and mozilla/layout).
*/
+class nsAtom;
class nsIContent;
class nsIDocument;
class imgRequestProxy;
class nsGenericHTMLElement;
namespace mozilla {
namespace dom {
class Element;
--- a/dom/base/nsNameSpaceManager.cpp
+++ b/dom/base/nsNameSpaceManager.cpp
@@ -8,16 +8,17 @@
* A class for managing namespace IDs and mapping back and forth
* between namespace IDs and namespace URIs.
*/
#include "nsNameSpaceManager.h"
#include "nscore.h"
#include "mozilla/dom/NodeInfo.h"
+#include "nsAtom.h"
#include "nsCOMArray.h"
#include "nsContentCreatorFunctions.h"
#include "nsGkAtoms.h"
#include "nsIDocument.h"
#include "nsString.h"
#include "mozilla/dom/NodeInfo.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/XBLChildrenElement.h"
--- a/layout/style/nsCSSAnonBoxes.cpp
+++ b/layout/style/nsCSSAnonBoxes.cpp
@@ -4,17 +4,16 @@
* 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 */
#include "mozilla/ArrayUtils.h"
#include "nsCSSAnonBoxes.h"
-#include "nsAtomListUtils.h"
#include "nsStaticAtom.h"
using namespace mozilla;
#define CSS_ANON_BOX(name_, value_) \
NS_STATIC_ATOM_SUBCLASS_DEFN(nsICSSAnonBoxPseudo, nsCSSAnonBoxes, name_)
#include "nsCSSAnonBoxList.h"
#undef CSS_ANON_BOX
@@ -42,18 +41,17 @@ static const nsStaticAtomSetup sCSSAnonB
void nsCSSAnonBoxes::AddRefAtoms()
{
NS_RegisterStaticAtoms(sCSSAnonBoxAtomSetup);
}
bool nsCSSAnonBoxes::IsAnonBox(nsAtom *aAtom)
{
- return nsAtomListUtils::IsMember(aAtom, sCSSAnonBoxAtomSetup,
- ArrayLength(sCSSAnonBoxAtomSetup));
+ return nsStaticAtomUtils::IsMember(aAtom, sCSSAnonBoxAtomSetup);
}
#ifdef MOZ_XUL
/* static */ bool
nsCSSAnonBoxes::IsTreePseudoElement(nsAtom* aPseudo)
{
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudo));
return StringBeginsWith(nsDependentAtomString(aPseudo),
--- a/layout/style/nsCSSPseudoElements.cpp
+++ b/layout/style/nsCSSPseudoElements.cpp
@@ -5,17 +5,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* atom list for CSS pseudo-elements */
#include "nsCSSPseudoElements.h"
#include "mozilla/ArrayUtils.h"
-#include "nsAtomListUtils.h"
#include "nsStaticAtom.h"
#include "nsCSSAnonBoxes.h"
#include "nsDOMString.h"
using namespace mozilla;
#define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
NS_STATIC_ATOM_BUFFER(name_, value_)
@@ -48,18 +47,17 @@ nsCSSPseudoElements::kPseudoElementFlags
void nsCSSPseudoElements::AddRefAtoms()
{
NS_RegisterStaticAtoms(sCSSPseudoElementAtomSetup);
}
bool nsCSSPseudoElements::IsPseudoElement(nsAtom *aAtom)
{
- return nsAtomListUtils::IsMember(aAtom, sCSSPseudoElementAtomSetup,
- ArrayLength(sCSSPseudoElementAtomSetup));
+ return nsStaticAtomUtils::IsMember(aAtom, sCSSPseudoElementAtomSetup);
}
/* static */ bool
nsCSSPseudoElements::IsCSS2PseudoElement(nsAtom *aAtom)
{
// We don't implement this using PseudoElementHasFlags because callers
// want to pass things that could be anon boxes.
NS_ASSERTION(nsCSSPseudoElements::IsPseudoElement(aAtom) ||
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -859,8 +859,21 @@ nsAtomTable::GetStaticAtom(const nsAStri
}
void
NS_SetStaticAtomsDone()
{
MOZ_ASSERT(NS_IsMainThread());
gStaticAtomsDone = true;
}
+
+/* static */ bool
+nsStaticAtomUtils::IsMember(nsAtom* aAtom, const nsStaticAtomSetup* aSetup,
+ uint32_t aCount)
+{
+ for (uint32_t i = 0; i < aCount; i++) {
+ if (aAtom == *(aSetup[i].mAtomp)) {
+ return true;
+ }
+ }
+ return false;
+}
+
--- a/xpcom/ds/nsStaticAtom.h
+++ b/xpcom/ds/nsStaticAtom.h
@@ -4,16 +4,17 @@
* 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/. */
#ifndef nsStaticAtom_h__
#define nsStaticAtom_h__
#include <stdint.h>
+class nsAtom;
class nsStaticAtom;
// The following macros are used to define static atoms, typically in
// conjunction with a .h file that defines the names and values of the atoms.
//
// For example, the .h file might be called MyAtomList.h and look like this:
//
// MY_ATOM(one, "one")
@@ -121,9 +122,23 @@ template<uint32_t N>
void
NS_RegisterStaticAtoms(const nsStaticAtomSetup (&aSetup)[N])
{
extern void RegisterStaticAtoms(const nsStaticAtomSetup* aSetup,
uint32_t aCount);
RegisterStaticAtoms(aSetup, N);
}
+// This class holds basic operations on arrays of static atoms.
+class nsStaticAtomUtils {
+public:
+ template<uint32_t N>
+ static bool IsMember(nsAtom *aAtom, const nsStaticAtomSetup (&aSetup)[N])
+ {
+ return IsMember(aAtom, aSetup, N);
+ }
+
+private:
+ static bool IsMember(nsAtom* aAtom, const nsStaticAtomSetup* aSetup,
+ uint32_t aCount);
+};
+
#endif