Skip to content

Commit

Permalink
chore(pacmak): use Map instead of object (#3757)
Browse files Browse the repository at this point in the history
---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
RomainMuller authored Sep 22, 2022
1 parent 783ec7f commit ad085eb
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/jsii-pacmak/lib/targets/go/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class RootPackage extends Package {
public readonly assembly: Assembly;
public readonly version: string;
private readonly versionFile: VersionFile;
private typeCache: Record<string, GoType | undefined> = {};
private readonly typeCache = new Map<string, GoType | undefined>();

// This cache of root packages is shared across all root packages derived created by this one (via dependencies).
private readonly rootPackageCache: Map<string, RootPackage>;
Expand Down Expand Up @@ -460,18 +460,21 @@ export class RootPackage extends Package {
* This allows resolving type references from other JSII modules
*/
public findType(fqn: string): GoType | undefined {
if (!this.typeCache[fqn]) {
this.typeCache[fqn] = this.packageDependencies.reduce(
(accum: GoType | undefined, current: RootPackage) => {
if (accum) {
return accum;
}
return current.findType(fqn);
},
super.findType(fqn),
if (!this.typeCache.has(fqn)) {
this.typeCache.set(
fqn,
this.packageDependencies.reduce(
(accum: GoType | undefined, current: RootPackage) => {
if (accum) {
return accum;
}
return current.findType(fqn);
},
super.findType(fqn),
),
);
}
return this.typeCache[fqn];
return this.typeCache.get(fqn);
}

/*
Expand Down

0 comments on commit ad085eb

Please sign in to comment.