Convert the RefSet primitive to a proper class and use a Set internally

The `RefSet` primitive predates ES6, so that most likely explains why an
object is used internally to track the entries. However, nowadays we can
use built-in JavaScript sets for this purpose. Built-in types are often
more efficient/optimized and using it makes the code a bit more clear
since we don't have to assign `true` to keys anymore just to indicate
their presence.
This commit is contained in:
Tim van der Meij 2020-06-07 18:51:05 +02:00
parent c97200ff59
commit 4c2e056796
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -221,28 +221,23 @@ var Ref = (function RefClosure() {
// The reference is identified by number and generation. // The reference is identified by number and generation.
// This structure stores only one instance of the reference. // This structure stores only one instance of the reference.
var RefSet = (function RefSetClosure() { class RefSet {
// eslint-disable-next-line no-shadow constructor() {
function RefSet() { this._set = new Set();
this.dict = Object.create(null);
} }
RefSet.prototype = { has(ref) {
has: function RefSet_has(ref) { return this._set.has(ref.toString());
return ref.toString() in this.dict; }
},
put: function RefSet_put(ref) { put(ref) {
this.dict[ref.toString()] = true; this._set.add(ref.toString());
}, }
remove: function RefSet_remove(ref) { remove(ref) {
delete this.dict[ref.toString()]; this._set.delete(ref.toString());
}, }
}; }
return RefSet;
})();
var RefSetCache = (function RefSetCacheClosure() { var RefSetCache = (function RefSetCacheClosure() {
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow