perf(core): use `array.push` / `array.pop` instead of `splice` if possible

This commit is contained in:
Tobias Bosch 2016-11-02 08:39:50 -07:00 committed by Vikram Subramanian
parent 0e3d655220
commit 0fc11a43f1
1 changed files with 13 additions and 2 deletions

View File

@ -104,7 +104,12 @@ export class ViewContainer {
nestedViews = [];
this.nestedViews = nestedViews;
}
nestedViews.splice(viewIndex, 0, view);
// perf: array.push is faster than array.splice!
if (viewIndex >= nestedViews.length) {
nestedViews.push(view);
} else {
nestedViews.splice(viewIndex, 0, view);
}
var refRenderNode: any /** TODO #9100 */;
if (viewIndex > 0) {
var prevView = nestedViews[viewIndex - 1];
@ -119,7 +124,13 @@ export class ViewContainer {
}
detachView(viewIndex: number): AppView<any> {
const view = this.nestedViews.splice(viewIndex, 1)[0];
const view = this.nestedViews[viewIndex];
// perf: array.pop is faster than array.splice!
if (viewIndex >= this.nestedViews.length - 1) {
this.nestedViews.pop();
} else {
this.nestedViews.splice(viewIndex, 1);
}
if (view.type === ViewType.COMPONENT) {
throw new Error(`Component views can't be moved!`);
}