From fe1f1ec79ab27578c6112a20c4bdba745dcf8cc3 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Wed, 12 Sep 2018 22:23:29 +0200 Subject: [PATCH] Fixed caching issue md5 was too slow. Fixes #236 --- lib/modifiedDOMRectAPI.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/modifiedDOMRectAPI.js b/lib/modifiedDOMRectAPI.js index e58f4fb..457a600 100644 --- a/lib/modifiedDOMRectAPI.js +++ b/lib/modifiedDOMRectAPI.js @@ -14,7 +14,7 @@ } const {hasType, checkerWrapper} = require("./modifiedAPIFunctions"); - const {md5String: hash} = require("./hash"); + const {byteArrayToString: hash} = require("./hash"); const getWrapped = require("sdk/getWrapped"); @@ -23,7 +23,6 @@ randomSupply = supply; }; - const cache = new Map(); function getHash(domRect){ return hash(new Float64Array([domRect.x, domRect.y, domRect.width, domRect.height])); } @@ -45,6 +44,8 @@ function getDOMRectRegistration(domRect){ return registeredRects.get(getWrapped(domRect)); } + + const cache = {}; function getFakeDomRect(window, domRect, prefs, notify){ var rng = randomSupply.getRng(4, window); @@ -57,7 +58,7 @@ } } const hash = getHash(domRect); - let cached = cache.get(hash); + let cached = cache[hash]; if (!cached){ notify("fakedDOMRectReadout"); cached = new domRect.constructor( @@ -66,7 +67,8 @@ getFakeValue(domRect.width, 2), getFakeValue(domRect.height, 3) ); - cache.set(getHash(cached), cached); + cache[hash] = cached; + cache[getHash(cached)] = cached; } return cached; }