From fadb2d9004d489947f4eab42df32f47b069f1db5 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 26 Nov 2019 14:28:03 +0000 Subject: [PATCH] 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 --- packages/core/src/render3/view_engine_compatibility.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index 623d2f663f..26834e538f 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -271,8 +271,12 @@ export function createContainerRef( throw new Error('Cannot move a destroyed View in a ViewContainer!'); } const index = this.indexOf(viewRef); - if (index !== -1) this.detach(index); - this.insert(viewRef, newIndex); + if (index === -1) { + this.insert(viewRef, newIndex); + } else if (index !== newIndex) { + this.detach(index); + this.insert(viewRef, newIndex); + } return viewRef; }