Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6dfc188

Browse files
committed
perf($compile): improving single-node case of replaceWith
1 parent c0fbf83 commit 6dfc188

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ng/compile.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24252425
i;
24262426

24272427
if ($rootElement && (i = indexOf.call($rootElement, firstElementToRemove)) !== -1) {
2428-
$rootElement.splice(i, removeCount, newNode);
2428+
if (removeCount === 1) {
2429+
$rootElement[i] = newNode;
2430+
} else {
2431+
$rootElement.splice(i, removeCount, newNode);
2432+
}
24292433

24302434
// If the replaced element is also the jQuery .context then replace it
24312435
// .context is a deprecated jQuery api, so we should set it only when jQuery set it
@@ -2477,7 +2481,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24772481
}
24782482

24792483
//Modify elementsToRemove jqLite/Array replacing all content with the newnode
2480-
elementsToRemove.splice(0, removeCount, newNode);
2484+
if (removeCount === 1) {
2485+
elementsToRemove[0] = newNode;
2486+
} else {
2487+
elementsToRemove.splice(0, removeCount, newNode);
2488+
}
24812489
}
24822490

24832491

0 commit comments

Comments
 (0)