Skip to content

Commit

Permalink
Prefix internal property.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlehn committed Mar 31, 2023
1 parent 3d15697 commit 1e25326
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/IdentifierIssuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module.exports = class IdentifierIssuer {
*/
constructor(prefix, existing = {refs: 0, map: new Map()}, counter = 0) {
this.prefix = prefix;
this.existing = existing;
this._existing = existing;
// add ref to shared map
this.existing.refs++;
this._existing.refs++;
this.counter = counter;
}

Expand All @@ -26,8 +26,8 @@ module.exports = class IdentifierIssuer {
* @return a copy of this IdentifierIssuer.
*/
clone() {
const {prefix, existing, counter} = this;
return new IdentifierIssuer(prefix, existing, counter);
const {prefix, _existing, counter} = this;
return new IdentifierIssuer(prefix, _existing, counter);
}

/**
Expand All @@ -40,7 +40,7 @@ module.exports = class IdentifierIssuer {
*/
getId(old) {
// return existing old identifier
const existing = old && this.existing.map.get(old);
const existing = old && this._existing.map.get(old);
if(existing) {
return existing;
}
Expand All @@ -51,7 +51,7 @@ module.exports = class IdentifierIssuer {

// save mapping
if(old) {
if(this.existing.refs > 1) {
if(this._existing.refs > 1) {
// copy-on-write shared map
// TODO: improve copy-on-write reference handling
// - current code handles copying the 'existing' maps when it is
Expand All @@ -63,14 +63,14 @@ module.exports = class IdentifierIssuer {
// - this won't result in errors, only extra copies if a child does
// not do an update, is done, and a parent then does an update
// unref shared map
this.existing.refs--;
this._existing.refs--;
// copy to new map
this.existing = {
this._existing = {
refs: 1,
map: new Map(this.existing.map)
map: new Map(this._existing.map)
};
}
this.existing.map.set(old, identifier);
this._existing.map.set(old, identifier);
}

return identifier;
Expand All @@ -86,7 +86,7 @@ module.exports = class IdentifierIssuer {
* false if not.
*/
hasId(old) {
return this.existing.map.has(old);
return this._existing.map.has(old);
}

/**
Expand All @@ -96,6 +96,6 @@ module.exports = class IdentifierIssuer {
* @return the list of old IDs that has been issued new IDs in order.
*/
getOldIds() {
return [...this.existing.map.keys()];
return [...this._existing.map.keys()];
}
};

0 comments on commit 1e25326

Please sign in to comment.