Remove DefaultAtoms. r=froydnj draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 13 Mar 2018 16:32:30 +1100
changeset 766617 12845d45a466b90ac319f0956ef1370017d0b999
parent 766616 faa72782d0e068610f288aa24d51382a7d9dd6e8
child 766618 792d3a81e77ff1919781a1b8b73272b02c5bfe0c
push id102371
push usernnethercote@mozilla.com
push dateTue, 13 Mar 2018 06:01:15 +0000
reviewersfroydnj
milestone60.0a1
Remove DefaultAtoms. r=froydnj Now that nsGkAtoms is in xpcom/, we can call nsGkAtoms::AddRefAtoms() from NS_InitAtomTable(), which removes the need for DefaultAtoms, and also removes a duplicate static atom. MozReview-Commit-ID: CyfvnvZomzZ
layout/build/nsLayoutStatics.cpp
xpcom/ds/nsAtomTable.cpp
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -142,24 +142,24 @@ nsLayoutStatics::Initialize()
   sLayoutStaticRefcnt = 1;
   NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
                 "nsLayoutStatics", 1);
 
   nsresult rv;
 
   ContentParent::StartUp();
 
-  // Register all of our atoms once
+  // Register static atoms. Note that nsGkAtoms must be initialized earlier
+  // than here, so it's done in NS_InitAtomTable() instead.
   nsCSSAnonBoxes::AddRefAtoms();
   nsCSSPseudoClasses::AddRefAtoms();
   nsCSSPseudoElements::AddRefAtoms();
   nsCSSKeywords::AddRefTable();
   nsCSSProps::AddRefTable();
   nsColorNames::AddRefTable();
-  nsGkAtoms::AddRefAtoms();
   nsRDFAtoms::RegisterAtoms();
 
   NS_SetStaticAtomsDone();
 
   StartupJSEnvironment();
 
   nsGlobalWindowInner::Init();
   nsGlobalWindowOuter::Init();
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -10,27 +10,28 @@
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/Unused.h"
 
 #include "nsAtom.h"
 #include "nsAtomTable.h"
+#include "nsAutoPtr.h"
+#include "nsCRT.h"
+#include "nsDataHashtable.h"
+#include "nsGkAtoms.h"
+#include "nsHashKeys.h"
+#include "nsPrintfCString.h"
 #include "nsStaticAtom.h"
 #include "nsString.h"
-#include "nsCRT.h"
+#include "nsThreadUtils.h"
+#include "nsUnicharUtils.h"
 #include "PLDHashTable.h"
 #include "prenv.h"
-#include "nsThreadUtils.h"
-#include "nsDataHashtable.h"
-#include "nsHashKeys.h"
-#include "nsAutoPtr.h"
-#include "nsUnicharUtils.h"
-#include "nsPrintfCString.h"
 
 // There are two kinds of atoms handled by this module.
 //
 // - Dynamic: the atom itself is heap allocated, as is the nsStringBuffer it
 //   points to. |gAtomTable| holds weak references to dynamic atoms. When the
 //   refcount of a dynamic atom drops to zero, we increment a static counter.
 //   When that counter reaches a certain threshold, we iterate over the atom
 //   table, removing and deleting dynamic atoms with refcount zero. This allows
@@ -601,43 +602,29 @@ nsAtom::Release()
   return IsStatic() ? 1 : nsDynamicAtom::As(this)->Release();
 }
 
 //----------------------------------------------------------------------
 
 // Have the static atoms been inserted into the table?
 static bool gStaticAtomsDone = false;
 
-class DefaultAtoms
-{
-public:
-  NS_STATIC_ATOM_DECL(empty)
-};
-
-NS_STATIC_ATOM_DEFN(DefaultAtoms, empty)
-
-NS_STATIC_ATOM_BUFFER(empty, "")
-
-static const nsStaticAtomSetup sDefaultAtomSetup[] = {
-  NS_STATIC_ATOM_SETUP(DefaultAtoms, empty)
-};
-
 void
 NS_InitAtomTable()
 {
   MOZ_ASSERT(!gAtomTable);
   gAtomTable = new nsAtomTable();
 
-  // Bug 1340710 has caused us to generate an empty atom at arbitrary times
-  // after startup.  If we end up creating one before nsGkAtoms::_empty is
-  // registered, we get an assertion about transmuting a dynamic atom into a
-  // static atom.  In order to avoid that, we register an empty string static
-  // atom as soon as we initialize the atom table to guarantee that the empty
-  // string atom will always be static.
-  NS_RegisterStaticAtoms(sDefaultAtomSetup);
+  // Bug 1340710 has caused us to use an empty atom at arbitrary times after
+  // startup. If we end up creating one before nsGkAtoms::_empty is registered,
+  // we get an assertion about transmuting a dynamic atom into a static atom.
+  // In order to avoid that, we register nsGkAtoms immediately after creating
+  // the atom table to guarantee that the empty string atom will always be
+  // static.
+  nsGkAtoms::AddRefAtoms();
 }
 
 void
 NS_ShutdownAtomTable()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(gAtomTable);