Bug 1425600 - Cache nsIPluginTag properties accessed in the plugin blocklist loop. r?Gijs draft
authorChris Peterson <cpeterson@mozilla.com>
Sun, 28 Jan 2018 14:10:11 -0800
changeset 748373 f9ce438820c26ed2dafe7c1bb9b04ff5a0a1fdbe
parent 748372 c0f08b020685f67a7ea08658731adb410f70b7e6
push id97140
push usercpeterson@mozilla.com
push dateMon, 29 Jan 2018 17:59:49 +0000
reviewersGijs
bugs1425600
milestone60.0a1
Bug 1425600 - Cache nsIPluginTag properties accessed in the plugin blocklist loop. r?Gijs On my MacBook Pro, this change reduces this loop's time from ~4 ms to ~3 ms. This loop is not hot, but moving these xpconnect calls out of the loop is still a good idea. MozReview-Commit-ID: ASwb6xZb6ur
toolkit/mozapps/extensions/nsBlocklistService.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -1106,32 +1106,39 @@ Blocklist.prototype = {
     if (!appVersion && !gApp.version)
       return Ci.nsIBlocklistService.STATE_NOT_BLOCKED;
 
     if (!appVersion)
       appVersion = gApp.version;
     if (!toolkitVersion)
       toolkitVersion = gApp.platformVersion;
 
+    const pluginProperties = {
+      description: plugin.description,
+      filename: plugin.filename,
+      name: plugin.name,
+    };
+    const pluginVersion = plugin.version;
+
     for (var blockEntry of pluginEntries) {
       var matchFailed = false;
       for (var name in blockEntry.matches) {
-        if (!(name in plugin) ||
-            typeof(plugin[name]) != "string" ||
-            !blockEntry.matches[name].test(plugin[name])) {
+        let pluginProperty = pluginProperties[name];
+        if (typeof(pluginProperty) !== "string" ||
+            !blockEntry.matches[name].test(pluginProperty)) {
           matchFailed = true;
           break;
         }
       }
 
       if (matchFailed)
         continue;
 
       for (let blockEntryVersion of blockEntry.versions) {
-        if (blockEntryVersion.includesItem(plugin.version, appVersion,
+        if (blockEntryVersion.includesItem(pluginVersion, appVersion,
                                            toolkitVersion)) {
           return {entry: blockEntry, version: blockEntryVersion};
         }
       }
     }
 
     return null;
   },