Bug 1454378 - make gfx blocklist processing faster, r?florian draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 13 Jun 2018 15:39:05 -0700
changeset 810883 82026d8bc8cea378e2d5740f7699b581f93bebf7
parent 810882 c7e45544d379cafab230c67213ff6f0ce193996e
child 810884 2d58c4a8e5820eeff80f6f626897bd121fd7f25a
push id114146
push userbmo:gijskruitbosch+bugs@gmail.com
push dateTue, 26 Jun 2018 17:15:11 +0000
reviewersflorian
bugs1454378
milestone63.0a1
Bug 1454378 - make gfx blocklist processing faster, r?florian MozReview-Commit-ID: A7Ydf6gUu3U
toolkit/mozapps/extensions/Blocklist.jsm
--- a/toolkit/mozapps/extensions/Blocklist.jsm
+++ b/toolkit/mozapps/extensions/Blocklist.jsm
@@ -1026,42 +1026,39 @@ var Blocklist = {
 
     // The blockID attribute is always present in the actual data produced on server
     // (see https://github.com/mozilla/addons-server/blob/2016.05.05/src/olympia/blocklist/templates/blocklist/blocklist.xml#L74)
     // But it is sometimes missing in test fixtures.
     if (blocklistElement.hasAttribute("blockID")) {
       blockEntry.blockID = blocklistElement.getAttribute("blockID");
     }
 
-    // Trim helper (spaces, tabs, no-break spaces..)
-    const trim = (s) => (s || "").replace(/(^[\s\uFEFF\xA0]+)|([\s\uFEFF\xA0]+$)/g, "");
-
     for (let matchElement of blocklistElement.children) {
       let value;
       if (matchElement.localName == "devices") {
         value = [];
         for (let childElement of matchElement.children) {
-          const childValue = trim(childElement.textContent);
+          const childValue = (childElement.textContent || "").trim();
           // Make sure no empty value is added.
           if (childValue) {
             if (/,/.test(childValue)) {
               // Devices can't contain comma.
               // (c.f serialization in _notifyObserversBlocklistGFX)
               const e = new Error(`Unsupported device name ${childValue}`);
               Cu.reportError(e);
             } else {
               value.push(childValue);
             }
           }
         }
       } else if (matchElement.localName == "versionRange") {
-        value = {minVersion: trim(matchElement.getAttribute("minVersion")) || "0",
-                 maxVersion: trim(matchElement.getAttribute("maxVersion")) || "*"};
+        value = {minVersion: (matchElement.getAttribute("minVersion") || "").trim() || "0",
+                 maxVersion: (matchElement.getAttribute("maxVersion") || "").trim() || "*"};
       } else {
-        value = trim(matchElement.textContent);
+        value = (matchElement.textContent || "").trim();
       }
       if (value) {
         blockEntry[matchElement.localName] = value;
       }
     }
     result.push(blockEntry);
   },
 
@@ -1189,31 +1186,41 @@ var Blocklist = {
     if (!blockEntry.blockID) {
       return null;
     }
 
     return blockEntry.infoURL || this._createBlocklistURL(blockEntry.blockID);
   },
 
   _notifyObserversBlocklistGFX() {
+    let sortedProps = [
+      "blockID", "devices", "driverVersion", "driverVersionComparator", "driverVersionMax",
+      "feature", "featureStatus", "hardware", "manufacturer", "model", "os", "osversion",
+      "product", "vendor", "versionRange",
+    ];
     // Notify `GfxInfoBase`, by passing a string serialization.
     // This way we avoid spreading XML structure logics there.
-    const payload = this._gfxEntries.map((r) => {
-      return Object.keys(r).sort().filter((k) => !/id|last_modified/.test(k)).map((key) => {
-        let value = r[key];
-        if (Array.isArray(value)) {
-          value = value.join(",");
-        } else if (value.hasOwnProperty("minVersion")) {
-          // When XML is parsed, both minVersion and maxVersion are set.
-          value = `${value.minVersion},${value.maxVersion}`;
+    let payload = [];
+    for (let gfxEntry of this._gfxEntries) {
+      let entryLines = [];
+      for (let key of sortedProps) {
+        if (gfxEntry[key]) {
+          let value = gfxEntry[key];
+          if (Array.isArray(value)) {
+            value = value.join(",");
+          } else if (value.maxVersion) {
+            // When XML is parsed, both minVersion and maxVersion are set.
+            value = value.minVersion + "," + value.maxVersion;
+          }
+          entryLines.push(key + ":" + value);
         }
-        return `${key}:${value}`;
-      }).join("\t");
-    }).join("\n");
-    Services.obs.notifyObservers(null, "blocklist-data-gfxItems", payload);
+      }
+      payload.push(entryLines.join("\t"));
+    }
+    Services.obs.notifyObservers(null, "blocklist-data-gfxItems", payload.join("\n"));
   },
 
   _notifyObserversBlocklistUpdated() {
     Services.obs.notifyObservers(this, "blocklist-updated");
   },
 
   async _blocklistUpdated(oldAddonEntries, oldPluginEntries) {
     var addonList = [];