Bug 1438497 part 2 - Do not report bindings which are cached in XUL prototype cache. r=bholley draft
authorXidorn Quan <me@upsuper.org>
Mon, 19 Feb 2018 17:27:08 +1100
changeset 757115 e696671d18970d710f6bfbca60c6014c51df9440
parent 756933 ec5b16d8d304382f200f90bc7650d4a41baa1006
child 757116 fe10ebd0d3b5538565e6e9692feb1cb993ef01a8
push id99670
push userxquan@mozilla.com
push dateTue, 20 Feb 2018 00:01:10 +0000
reviewersbholley
bugs1438497
milestone60.0a1
Bug 1438497 part 2 - Do not report bindings which are cached in XUL prototype cache. r=bholley MozReview-Commit-ID: 7ZqQswt7QtA
dom/xbl/nsBindingManager.cpp
--- a/dom/xbl/nsBindingManager.cpp
+++ b/dom/xbl/nsBindingManager.cpp
@@ -27,16 +27,19 @@
 #include "nsIStreamListener.h"
 #include "ChildIterator.h"
 #include "nsITimer.h"
 
 #include "nsXBLBinding.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsXBLDocumentInfo.h"
 #include "mozilla/dom/XBLChildrenElement.h"
+#ifdef MOZ_XUL
+#include "nsXULPrototypeCache.h"
+#endif
 
 #ifdef MOZ_OLD_STYLE
 #include "nsIStyleRuleProcessor.h"
 #include "nsRuleProcessorData.h"
 #endif
 #include "nsIWeakReference.h"
 
 #include "nsWrapperCacheInlines.h"
@@ -1125,16 +1128,29 @@ nsBindingManager::SizeOfIncludingThis(Ma
   SHALLOW_SIZE_INCLUDING(mBoundContentSet);
   SHALLOW_SIZE_INCLUDING(mWrapperTable);
   SHALLOW_SIZE_INCLUDING(mLoadingDocTable);
 #undef SHALLOW_SIZE_INCLUDING
   n += mAttachedStack.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
   if (mDocumentTable) {
     n += mDocumentTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
+#ifdef MOZ_XUL
+    nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
+    StyleBackendType backendType = mDocument->GetStyleBackendType();
+#endif
     for (auto iter = mDocumentTable->Iter(); !iter.Done(); iter.Next()) {
       nsXBLDocumentInfo* docInfo = iter.UserData();
+#ifdef MOZ_XUL
+      nsXBLDocumentInfo* cachedInfo =
+        cache->GetXBLDocumentInfo(iter.Key(), backendType);
+      if (cachedInfo == docInfo) {
+        // If this binding has been cached, skip it since it can be
+        // reused by other documents.
+        continue;
+      }
+#endif
       n += docInfo->SizeOfIncludingThis(aMallocSizeOf);
     }
   }
 
   return n;
 }