1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-11-01 02:48:44 +01:00

Fixed caching issue

md5 was too slow.

Fixes #236
This commit is contained in:
kkapsner 2018-09-12 22:23:29 +02:00
parent c798e2b412
commit fe1f1ec79a

View File

@ -14,7 +14,7 @@
} }
const {hasType, checkerWrapper} = require("./modifiedAPIFunctions"); const {hasType, checkerWrapper} = require("./modifiedAPIFunctions");
const {md5String: hash} = require("./hash"); const {byteArrayToString: hash} = require("./hash");
const getWrapped = require("sdk/getWrapped"); const getWrapped = require("sdk/getWrapped");
@ -23,7 +23,6 @@
randomSupply = supply; randomSupply = supply;
}; };
const cache = new Map();
function getHash(domRect){ function getHash(domRect){
return hash(new Float64Array([domRect.x, domRect.y, domRect.width, domRect.height])); return hash(new Float64Array([domRect.x, domRect.y, domRect.width, domRect.height]));
} }
@ -45,6 +44,8 @@
function getDOMRectRegistration(domRect){ function getDOMRectRegistration(domRect){
return registeredRects.get(getWrapped(domRect)); return registeredRects.get(getWrapped(domRect));
} }
const cache = {};
function getFakeDomRect(window, domRect, prefs, notify){ function getFakeDomRect(window, domRect, prefs, notify){
var rng = randomSupply.getRng(4, window); var rng = randomSupply.getRng(4, window);
@ -57,7 +58,7 @@
} }
} }
const hash = getHash(domRect); const hash = getHash(domRect);
let cached = cache.get(hash); let cached = cache[hash];
if (!cached){ if (!cached){
notify("fakedDOMRectReadout"); notify("fakedDOMRectReadout");
cached = new domRect.constructor( cached = new domRect.constructor(
@ -66,7 +67,8 @@
getFakeValue(domRect.width, 2), getFakeValue(domRect.width, 2),
getFakeValue(domRect.height, 3) getFakeValue(domRect.height, 3)
); );
cache.set(getHash(cached), cached); cache[hash] = cached;
cache[getHash(cached)] = cached;
} }
return cached; return cached;
} }