Skip to content

Commit

Permalink
perf(core): optimize reflector
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Aug 14, 2022
1 parent 6363cbe commit a3b8256
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/services/reflector.service.ts
Expand Up @@ -23,7 +23,7 @@ export class Reflector {
metadataKey: TKey,
target: Type<any> | Function,
): TResult {
return Reflect.getMetadata(metadataKey, target) as TResult;
return Reflect.getMetadata(metadataKey, target);
}

/**
Expand All @@ -38,7 +38,7 @@ export class Reflector {
targets: (Type<any> | Function)[],
): TResult {
return (targets || []).map(target =>
Reflect.getMetadata(metadataKey, target),
this.get(metadataKey, target),
) as TResult;
}

Expand Down Expand Up @@ -86,6 +86,12 @@ export class Reflector {
metadataKey: TKey,
targets: (Type<any> | Function)[],
): TResult {
return this.getAll(metadataKey, targets).find(item => item !== undefined);
for (const target of targets) {
const result = this.get(metadataKey, target);
if (result !== undefined) {
return result;
}
}
return undefined;
}
}

0 comments on commit a3b8256

Please sign in to comment.