Bug 1356835 - Reduce the hashtable lookup cost in nsContentPolicy::CheckPolicy(); r=qdot
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 15 Apr 2017 16:23:37 -0400
changeset 403849 938824ac57496e64e634e4a658b5b531de9e69ac
parent 403848 616974bb80233137522000496f7e240bf2a0eb2b
child 403850 364c11f78435c92541485253850a6087363f39a7
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1356835
milestone55.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 1356835 - Reduce the hashtable lookup cost in nsContentPolicy::CheckPolicy(); r=qdot
dom/base/nsContentPolicy.cpp
dom/base/nsContentPolicy.h
--- a/dom/base/nsContentPolicy.cpp
+++ b/dom/base/nsContentPolicy.cpp
@@ -40,16 +40,18 @@ NS_NewContentPolicy(nsIContentPolicy **a
   *aResult = new nsContentPolicy;
   NS_ADDREF(*aResult);
   return NS_OK;
 }
 
 nsContentPolicy::nsContentPolicy()
     : mPolicies(NS_CONTENTPOLICY_CATEGORY)
     , mSimplePolicies(NS_SIMPLECONTENTPOLICY_CATEGORY)
+    , mMixedContentBlocker(do_GetService(NS_MIXEDCONTENTBLOCKER_CONTRACTID))
+    , mCSPService(do_GetService(CSPSERVICE_CONTRACTID))
 {
 }
 
 nsContentPolicy::~nsContentPolicy()
 {
 }
 
 #ifdef DEBUG
@@ -113,22 +115,16 @@ nsContentPolicy::CheckPolicy(CPMethod   
         if (doc) {
             requestingLocation = doc->GetDocumentURI();
         }
     }
 
     nsContentPolicyType externalType =
         nsContentUtils::InternalContentPolicyTypeToExternal(contentType);
 
-    nsCOMPtr<nsIContentPolicy> mixedContentBlocker =
-        do_GetService(NS_MIXEDCONTENTBLOCKER_CONTRACTID);
-
-    nsCOMPtr<nsIContentPolicy> cspService =
-      do_GetService(CSPSERVICE_CONTRACTID);
-
     /* 
      * Enumerate mPolicies and ask each of them, taking the logical AND of
      * their permissions.
      */
     nsresult rv;
     nsCOMArray<nsIContentPolicy> entries;
     mPolicies.GetEntries(entries);
 
@@ -147,17 +143,17 @@ nsContentPolicy::CheckPolicy(CPMethod   
         }
     }
 
     int32_t count = entries.Count();
     for (int32_t i = 0; i < count; i++) {
         /* check the appropriate policy */
         // Send internal content policy type to CSP and mixed content blocker
         nsContentPolicyType type = externalType;
-        if (mixedContentBlocker == entries[i] || cspService == entries[i]) {
+        if (mMixedContentBlocker == entries[i] || mCSPService == entries[i]) {
           type = contentType;
         }
         rv = (entries[i]->*policyMethod)(type, contentLocation,
                                          requestingLocation, requestingContext,
                                          mimeType, extra, requestPrincipal,
                                          decision);
 
         if (NS_SUCCEEDED(rv) && NS_CP_REJECTED(*decision)) {
--- a/dom/base/nsContentPolicy.h
+++ b/dom/base/nsContentPolicy.h
@@ -26,16 +26,19 @@ class nsContentPolicy : public nsIConten
  protected:
     virtual ~nsContentPolicy();
 
  private:
     //Array of policies
     nsCategoryCache<nsIContentPolicy> mPolicies;
     nsCategoryCache<nsISimpleContentPolicy> mSimplePolicies;
 
+    nsCOMPtr<nsIContentPolicy> mMixedContentBlocker;
+    nsCOMPtr<nsIContentPolicy> mCSPService;
+
     //Helper type for CheckPolicy
     typedef
     NS_STDCALL_FUNCPROTO(nsresult, CPMethod, nsIContentPolicy,
                          ShouldProcess,
                          (uint32_t, nsIURI*, nsIURI*, nsISupports*,
                            const nsACString &, nsISupports*, nsIPrincipal*,
                            int16_t*));