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

Commit b1d2a8b

Browse files
committed
perf($compile): improving single-node case of replaceWith
1 parent e62fafb commit b1d2a8b

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
@@ -2400,7 +2400,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24002400
i;
24012401

24022402
if ($rootElement && (i = indexOf.call($rootElement, firstElementToRemove)) !== -1) {
2403-
$rootElement.splice(i, removeCount, newNode);
2403+
if (removeCount === 1) {
2404+
$rootElement[i] = newNode;
2405+
} else {
2406+
$rootElement.splice(i, removeCount, newNode);
2407+
}
24042408

24052409
// If the replaced element is also the jQuery .context then replace it
24062410
// .context is a deprecated jQuery api, so we should set it only when jQuery set it
@@ -2452,7 +2456,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24522456
}
24532457

24542458
//Modify elementsToRemove jqLite/Array replacing all content with the newnode
2455-
elementsToRemove.splice(0, removeCount, newNode);
2459+
if (removeCount === 1) {
2460+
elementsToRemove[0] = newNode;
2461+
} else {
2462+
elementsToRemove.splice(0, removeCount, newNode);
2463+
}
24562464
}
24572465

24582466

0 commit comments

Comments
 (0)