mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
perf(core): optimize reflector
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user