perf(core): optimize reflector

This commit is contained in:
ZanMinKian
2022-08-14 19:21:29 +00:00
parent 6363cbe29d
commit a3b8256d60

View File

@@ -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;
}
}