You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
16 KiB
1 line
16 KiB
5 months ago
|
{"version":3,"file":"bundle.cjs","sources":["es5/strong.js","es5/weak.js"],"sourcesContent":["function defaultDispose() { }\nvar StrongCache = /** @class */ (function () {\n function StrongCache(max, dispose) {\n if (max === void 0) { max = Infinity; }\n if (dispose === void 0) { dispose = defaultDispose; }\n this.max = max;\n this.dispose = dispose;\n this.map = new Map();\n this.newest = null;\n this.oldest = null;\n }\n StrongCache.prototype.has = function (key) {\n return this.map.has(key);\n };\n StrongCache.prototype.get = function (key) {\n var node = this.getNode(key);\n return node && node.value;\n };\n Object.defineProperty(StrongCache.prototype, \"size\", {\n get: function () {\n return this.map.size;\n },\n enumerable: false,\n configurable: true\n });\n StrongCache.prototype.getNode = function (key) {\n var node = this.map.get(key);\n if (node && node !== this.newest) {\n var older = node.older, newer = node.newer;\n if (newer) {\n newer.older = older;\n }\n if (older) {\n older.newer = newer;\n }\n node.older = this.newest;\n node.older.newer = node;\n node.newer = null;\n this.newest = node;\n if (node === this.oldest) {\n this.oldest = newer;\n }\n }\n return node;\n };\n StrongCache.prototype.set = function (key, value) {\n var node = this.getNode(key);\n if (node) {\n return node.value = value;\n }\n node = {\n key: key,\n value: value,\n newer: null,\n older: this.newest\n };\n if (this.newest) {\n this.newest.newer = node;\n }\n this.newest = node;\n this.oldest = this.oldest || node;\n this.map.set(key, node);\n return node.value;\n };\n StrongCache.prototype.clean = function () {\n while (this.oldest && this.map.size > this.max) {\n this.delete(this.oldest.key);\n }\n };\n StrongCache.prototype.delete = function (key) {\n var node = this.map.get(key);\n if (node) {\n if (node === this.newest) {\n this.newest = node.older;\n }\n if (node === this.oldest) {\n this.oldest = node.newer;\n }\n if (node.newer) {\n node.newer.older = node.older;\n }\n if (node.older) {\n node.older.newer = node.newer;\n }\n this.map.delete(key);\n this.dispose(node.value, key);\n return true;\n }\n return false;\n };\n return StrongCache;\n}());\nexport { StrongCache };\n//# sourceMappingURL=strong.js.map","function noop() { }\nvar defaultDispose = noop;\nvar _WeakRef = typeof WeakRef !== \"undefined\"\n ? WeakRef\n : function (value) {\n return { deref: function () { return value; } };\n };\nvar _WeakMap = typeof WeakMap !== \"undefined\" ? WeakMap : Map;\nvar _FinalizationRegistry = typeof FinalizationRegistry !== \"undefined\"\n ? FinalizationRegistry\n : function () {\n return {\n register: noop,\n unregister: noop,\n };\n };\nvar finalizationBatchSize = 10024;\nvar WeakCache = /** @class */ (function () {\n function WeakCache(max, dispose) {\n if (max === void 0) { max = Infinity; }\n if (dispose === void 0) { dispose = defaultDispose; }\n var _this = this;\n this.max = max;\n this.dispose = dispose;\n this.map = new _WeakMap();\n this.newest = null;\n this.oldest = null;\n this.unfinalizedNodes = new Set();\n this.finalizationScheduled = false;\n this.size = 0;\n this.finalize = function () {\n var iterator = _this.unfinalizedNodes.values();\n
|