Bug 1168007 (part 3) - Use PLDHashTable2 in nsContentSupportMap. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 18 May 2015 20:21:16 -0700
changeset 246138 ab7314eca092d74f10d41a2c7022b09d46cb9b0d
parent 246137 8a618ebbb4d6aeb41c2f4bb52af24c39bb0586be
child 246139 c8123d60e270ff612e4203cb79d120a0e26ddf0e
push id60380
push usernnethercote@mozilla.com
push dateFri, 29 May 2015 03:47:23 +0000
treeherdermozilla-inbound@c8123d60e270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1168007
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168007 (part 3) - Use PLDHashTable2 in nsContentSupportMap. r=froydnj.
dom/xul/templates/nsContentSupportMap.cpp
dom/xul/templates/nsContentSupportMap.h
--- a/dom/xul/templates/nsContentSupportMap.cpp
+++ b/dom/xul/templates/nsContentSupportMap.cpp
@@ -1,29 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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/. */
 
 #include "nsContentSupportMap.h"
 #include "nsXULElement.h"
 
-void
-nsContentSupportMap::Init()
-{
-    PL_DHashTableInit(&mMap, PL_DHashGetStubOps(), sizeof(Entry));
-}
-
-void
-nsContentSupportMap::Finish()
-{
-    if (mMap.IsInitialized())
-        PL_DHashTableFinish(&mMap);
-}
-
 nsresult
 nsContentSupportMap::Remove(nsIContent* aElement)
 {
     if (!mMap.IsInitialized())
         return NS_ERROR_NOT_INITIALIZED;
 
     nsIContent* child = aElement;
     do {
--- a/dom/xul/templates/nsContentSupportMap.h
+++ b/dom/xul/templates/nsContentSupportMap.h
@@ -16,57 +16,48 @@
  * when building "resumes" on a partially-built content element, the builder
  * will walk upwards in the content tree to find the first element with an
  * 'id' attribute. This element is assumed to be the "resource element",
  * and allows the content builder to access the nsTemplateMatch (variable assignments
  * and rule information).
  */
 class nsContentSupportMap {
 public:
-    nsContentSupportMap() { Init(); }
-    ~nsContentSupportMap() { Finish(); }
+    nsContentSupportMap() : mMap(PL_DHashGetStubOps(), sizeof(Entry)) { }
+    ~nsContentSupportMap() { }
 
     nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) {
-        if (!mMap.IsInitialized())
-            return NS_ERROR_NOT_INITIALIZED;
-
         PLDHashEntryHdr* hdr =
             PL_DHashTableAdd(&mMap, aElement, mozilla::fallible);
         if (!hdr)
             return NS_ERROR_OUT_OF_MEMORY;
 
         Entry* entry = static_cast<Entry*>(hdr);
         NS_ASSERTION(entry->mMatch == nullptr, "over-writing entry");
         entry->mContent = aElement;
         entry->mMatch   = aMatch;
         return NS_OK;
     }
 
     bool Get(nsIContent* aElement, nsTemplateMatch** aMatch) {
-        if (!mMap.IsInitialized())
-            return false;
-
         PLDHashEntryHdr* hdr = PL_DHashTableSearch(&mMap, aElement);
         if (!hdr)
             return false;
 
         Entry* entry = static_cast<Entry*>(hdr);
         *aMatch = entry->mMatch;
         return true;
     }
 
     nsresult Remove(nsIContent* aElement);
 
-    void Clear() { Finish(); Init(); }
+    void Clear() { mMap.Clear(); }
 
 protected:
-    PLDHashTable mMap;
-
-    void Init();
-    void Finish();
+    PLDHashTable2 mMap;
 
     struct Entry : public PLDHashEntryHdr {
         nsIContent*      mContent;
         nsTemplateMatch* mMatch;
     };
 };
 
 #endif