perf(forms): optimize internal method _anyControls in FormGroup (#32534)
The method was previously looping through all controls, even after finding at least one that satisfies the provided condition. This can be a bottleneck with large forms. The new version of the method returns as soon as a single control which conforms to the condition is found. PR Close #32534
This commit is contained in:
parent
e0dfa42d6e
commit
2a145f2463
|
@ -1593,11 +1593,13 @@ export class FormGroup extends AbstractControl {
|
|||
|
||||
/** @internal */
|
||||
_anyControls(condition: Function): boolean {
|
||||
let res = false;
|
||||
this._forEachChild((control: AbstractControl, name: string) => {
|
||||
res = res || (this.contains(name) && condition(control));
|
||||
});
|
||||
return res;
|
||||
for (const controlName of Object.keys(this.controls)) {
|
||||
const control = this.controls[controlName];
|
||||
if (this.contains(controlName) && condition(control)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
|
Loading…
Reference in New Issue