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 */
|
/** @internal */
|
||||||
_anyControls(condition: Function): boolean {
|
_anyControls(condition: Function): boolean {
|
||||||
let res = false;
|
for (const controlName of Object.keys(this.controls)) {
|
||||||
this._forEachChild((control: AbstractControl, name: string) => {
|
const control = this.controls[controlName];
|
||||||
res = res || (this.contains(name) && condition(control));
|
if (this.contains(controlName) && condition(control)) {
|
||||||
});
|
return true;
|
||||||
return res;
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
|
Loading…
Reference in New Issue