Bug 1276669 - Part 10: Remove dynamic->static atom transmutation code. r=erahm, a=ritu
authorNathan Froyd <froydnj@mozilla.com>
Thu, 26 Jan 2017 15:43:38 -0500
changeset 375827 8ee370bffd15ed59c401285dac62e7f24d4f15ef
parent 375826 2159ed149364daaadd4da371c00c4809cd5c3490
child 375828 b4ed5ea97d2553ad845bf31e746d767b4bffa50a
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm, ritu
bugs1276669
milestone53.0a2
Bug 1276669 - Part 10: Remove dynamic->static atom transmutation code. r=erahm, a=ritu Good riddance to some sketchy code.
xpcom/ds/nsAtomTable.cpp
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -116,55 +116,21 @@ private:
 private:
   // We don't need a virtual destructor because we always delete via a
   // DynamicAtom* pointer (in GCAtomTable()), not an nsIAtom* pointer.
   ~DynamicAtom();
 
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIATOM
-
-  void TransmuteToStatic(nsStringBuffer* aStringBuffer);
 };
 
 class StaticAtom final : public nsIAtom
 {
-  // This is the function that calls the private constructor.
-  friend void DynamicAtom::TransmuteToStatic(nsStringBuffer*);
-
-  // This constructor must only be used in conjunction with placement new on an
-  // existing DynamicAtom (in DynamicAtom::TransmuteToStatic()) in order to
-  // transmute that DynamicAtom into a StaticAtom. The constructor does four
-  // notable things.
-  // - Overwrites the vtable pointer (implicitly).
-  // - Inverts mIsStatic.
-  // - Zeroes the refcount (via the nsIAtom constructor). Having a zero refcount
-  //   doesn't matter because StaticAtom's AddRef/Release methods don't consult
-  //   the refcount.
-  // - Releases the existing heap-allocated string buffer (explicitly),
-  //   replacing it with the static string buffer (which must contain identical
-  //   chars).
-  explicit StaticAtom(nsStringBuffer* aStaticBuffer)
-  {
-    static_assert(sizeof(DynamicAtom) >= sizeof(StaticAtom),
-                  "can't safely transmute a smaller object to a bigger one");
-
-    // We must be transmuting an existing DynamicAtom.
-    MOZ_ASSERT(!mIsStatic);
-    mIsStatic = true;
-
-    char16_t* staticString = static_cast<char16_t*>(aStaticBuffer->Data());
-    MOZ_ASSERT(nsCRT::strcmp(staticString, mString) == 0);
-    nsStringBuffer* dynamicBuffer = nsStringBuffer::FromData(mString);
-    mString = staticString;
-    dynamicBuffer->Release();
-  }
-
 public:
-  // This is the normal constructor.
   StaticAtom(nsStringBuffer* aStringBuffer, uint32_t aLength, uint32_t aHash)
   {
     mLength = aLength;
     mIsStatic = true;
     mString = static_cast<char16_t*>(aStringBuffer->Data());
     // Technically we could currently avoid doing this addref by instead making
     // the static atom buffers have an initial refcount of 2.
     aStringBuffer->AddRef();
@@ -255,24 +221,16 @@ NS_IMETHODIMP_(size_t)
 StaticAtom::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
 {
   size_t n = aMallocSizeOf(this);
   // Don't measure the string buffer pointed to by the StaticAtom because it's
   // in static memory.
   return n;
 }
 
-// See the comment on the private StaticAtom constructor for details of how
-// this works.
-void
-DynamicAtom::TransmuteToStatic(nsStringBuffer* aStringBuffer)
-{
-  new (this) StaticAtom(aStringBuffer);
-}
-
 //----------------------------------------------------------------------
 
 /**
  * The shared hash table for atom lookups.
  *
  * Callers must hold gAtomTableLock before manipulating the table.
  */
 static PLDHashTable* gAtomTable;