perf(ivy): do no work if moving a `viewRef` to the same position (#34052)

Move a view only if it would end up at a different place.
Otherwise we would do unnecessary processing like DOM manipulation, query notifications etc.

Thanks to @pkozlowski-opensource for the change.

PR Close #34052
This commit is contained in:
Pete Bacon Darwin 2019-11-26 14:28:03 +00:00 committed by Matias Niemelä
parent f0f426b2d0
commit fadb2d9004
1 changed files with 6 additions and 2 deletions

View File

@ -271,8 +271,12 @@ export function createContainerRef(
throw new Error('Cannot move a destroyed View in a ViewContainer!'); throw new Error('Cannot move a destroyed View in a ViewContainer!');
} }
const index = this.indexOf(viewRef); const index = this.indexOf(viewRef);
if (index !== -1) this.detach(index); if (index === -1) {
this.insert(viewRef, newIndex); this.insert(viewRef, newIndex);
} else if (index !== newIndex) {
this.detach(index);
this.insert(viewRef, newIndex);
}
return viewRef; return viewRef;
} }