Skip to content

Commit

Permalink
Fix performance problem with Reflection.getAlias
Browse files Browse the repository at this point in the history
Resolves #1755
  • Loading branch information
Gerrit0 committed Oct 22, 2021
1 parent 0fedd05 commit 4557ed3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### Bug Fixes

- Replaced O(n^2) with O(1) implementation for determining unique IDs in a rendered page, #1755.
- Fixed visible gap after footer in dark mode if `hideGenerator` is set, #1749.
- Fixed `@category` tag incorrectly appearing on function types if used on a type alias, #1745.
- Fixed incorrect JS to apply themes on page load, #1709 (again).
Expand Down
17 changes: 10 additions & 7 deletions src/lib/models/reflections/abstract.ts
Expand Up @@ -409,7 +409,7 @@ export abstract class Reflection {
*/
private _alias?: string;

private _aliases?: string[];
private _aliases?: Map<string, number>;

/**
* Create a new BaseReflection instance.
Expand Down Expand Up @@ -478,16 +478,19 @@ export abstract class Reflection {
}

if (!target._aliases) {
target._aliases = [];
target._aliases = new Map();
}
let suffix = "",
index = 0;
while (target._aliases.includes(alias + suffix)) {
suffix = "-" + (++index).toString();

let suffix = "";
if (!target._aliases.has(alias)) {
target._aliases.set(alias, 1);
} else {
const count = target._aliases.get(alias)!;
suffix = "-" + count.toString();
target._aliases.set(alias, count + 1);
}

alias += suffix;
target._aliases.push(alias);
this._alias = alias;
}

Expand Down

0 comments on commit 4557ed3

Please sign in to comment.