Bug 1402944: Part 11 - Use number rather than string value for getUniqueId(). r?mixedpuppy
This allows us to avoid a fairly expensive stringification/string allocation
when calling getUniqueId(), which is helpful. It also allows us to avoid
atomizing the ID string when storing it in a Set or Map, which is even more
helpful. And, of course, it makes comparisons faster.
MozReview-Commit-ID: 8wMc6TdhzfY
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -23,20 +23,25 @@ function getConsole() {
});
}
XPCOMUtils.defineLazyGetter(this, "console", getConsole);
const appinfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
let nextId = 0;
-const uniqueProcessID = String(appinfo.uniqueProcessID);
+const uniqueProcessID = appinfo.uniqueProcessID;
+// Store the process ID in a 16 bit field left shifted to end of a
+// double's mantissa.
+const processIDMask = uniqueProcessID * (2 ** 37);
function getUniqueId() {
- return `${nextId++}-${uniqueProcessID}`;
+ // Note: We can't use bitwise ops here, since they truncate to a 32 bit
+ // integer and we need all 52 mantissa bits.
+ return processIDMask + nextId++;
}
/**
* An Error subclass for which complete error messages are always passed
* to extensions, rather than being interpreted as an unknown error.
*/
class ExtensionError extends Error {}