77 */
88
99import { ViewEncapsulation } from '../metadata/view' ;
10- import { assertDefined } from '../util/assert' ;
1110
1211import { assertLContainer , assertLView } from './assert' ;
1312import { attachPatchData } from './context_discovery' ;
14- import { LContainer , NATIVE , VIEWS , unusedValueExportToPlacateAjd as unused1 } from './interfaces/container' ;
13+ import { CONTAINER_HEADER_OFFSET , LContainer , NATIVE , unusedValueExportToPlacateAjd as unused1 } from './interfaces/container' ;
1514import { ComponentDef } from './interfaces/definition' ;
1615import { NodeInjectorFactory } from './interfaces/injector' ;
1716import { TElementNode , TNode , TNodeFlags , TNodeType , TProjectionNode , TViewNode , unusedValueExportToPlacateAjd as unused2 } from './interfaces/node' ;
@@ -99,8 +98,9 @@ function walkTNodeTree(
9998 // This element has an LContainer, and its comment needs to be handled
10099 executeNodeAction (
101100 action , renderer , renderParent , nodeOrContainer [ NATIVE ] , tNode , beforeNode ) ;
102- if ( nodeOrContainer [ VIEWS ] . length ) {
103- currentView = nodeOrContainer [ VIEWS ] [ 0 ] ;
101+ const firstView = nodeOrContainer [ CONTAINER_HEADER_OFFSET ] ;
102+ if ( firstView ) {
103+ currentView = firstView ;
104104 nextTNode = currentView [ TVIEW ] . node ;
105105
106106 // When the walker enters a container, then the beforeNode has to become the local native
@@ -111,9 +111,9 @@ function walkTNodeTree(
111111 } else if ( tNode . type === TNodeType . Container ) {
112112 const lContainer = currentView ! [ tNode . index ] as LContainer ;
113113 executeNodeAction ( action , renderer , renderParent , lContainer [ NATIVE ] , tNode , beforeNode ) ;
114-
115- if ( lContainer [ VIEWS ] . length ) {
116- currentView = lContainer [ VIEWS ] [ 0 ] ;
114+ const firstView = lContainer [ CONTAINER_HEADER_OFFSET ] ;
115+ if ( firstView ) {
116+ currentView = firstView ;
117117 nextTNode = currentView [ TVIEW ] . node ;
118118
119119 // When the walker enters a container, then the beforeNode has to become the local native
@@ -302,8 +302,8 @@ export function destroyViewTree(rootView: LView): void {
302302 } else {
303303 ngDevMode && assertLContainer ( lViewOrLContainer ) ;
304304 // If container, traverse down to its first LView.
305- const views = lViewOrLContainer [ VIEWS ] as LView [ ] ;
306- if ( views . length > 0 ) next = views [ 0 ] ;
305+ const firstView : LView | undefined = lViewOrLContainer [ CONTAINER_HEADER_OFFSET ] ;
306+ if ( firstView ) next = firstView ;
307307 }
308308
309309 if ( ! next ) {
@@ -335,18 +335,18 @@ export function destroyViewTree(rootView: LView): void {
335335export function insertView ( lView : LView , lContainer : LContainer , index : number ) {
336336 ngDevMode && assertLView ( lView ) ;
337337 ngDevMode && assertLContainer ( lContainer ) ;
338- const views = lContainer [ VIEWS ] ;
339- ngDevMode && assertDefined ( views , 'Container must have views' ) ;
338+ const indexInContainer = CONTAINER_HEADER_OFFSET + index ;
339+ const containerLength = lContainer . length ;
340+
340341 if ( index > 0 ) {
341342 // This is a new view, we need to add it to the children.
342- views [ index - 1 ] [ NEXT ] = lView ;
343+ lContainer [ indexInContainer - 1 ] [ NEXT ] = lView ;
343344 }
344-
345- if ( index < views . length ) {
346- lView [ NEXT ] = views [ index ] ;
347- views . splice ( index , 0 , lView ) ;
345+ if ( index < containerLength - CONTAINER_HEADER_OFFSET ) {
346+ lView [ NEXT ] = lContainer [ indexInContainer ] ;
347+ lContainer . splice ( CONTAINER_HEADER_OFFSET + index , 0 , lView ) ;
348348 } else {
349- views . push ( lView ) ;
349+ lContainer . push ( lView ) ;
350350 lView [ NEXT ] = null ;
351351 }
352352
@@ -372,13 +372,15 @@ export function insertView(lView: LView, lContainer: LContainer, index: number)
372372 * @returns Detached LView instance.
373373 */
374374export function detachView ( lContainer : LContainer , removeIndex : number ) : LView | undefined {
375- const views = lContainer [ VIEWS ] ;
376- const viewToDetach = views [ removeIndex ] ;
375+ if ( lContainer . length <= CONTAINER_HEADER_OFFSET ) return ;
376+
377+ const indexInContainer = CONTAINER_HEADER_OFFSET + removeIndex ;
378+ const viewToDetach = lContainer [ indexInContainer ] ;
377379 if ( viewToDetach ) {
378380 if ( removeIndex > 0 ) {
379- views [ removeIndex - 1 ] [ NEXT ] = viewToDetach [ NEXT ] as LView ;
381+ lContainer [ indexInContainer - 1 ] [ NEXT ] = viewToDetach [ NEXT ] as LView ;
380382 }
381- views . splice ( removeIndex , 1 ) ;
383+ lContainer . splice ( CONTAINER_HEADER_OFFSET + removeIndex , 1 ) ;
382384 addRemoveViewFromContainer ( viewToDetach , false ) ;
383385
384386 if ( ( viewToDetach [ FLAGS ] & LViewFlags . Attached ) &&
@@ -400,11 +402,8 @@ export function detachView(lContainer: LContainer, removeIndex: number): LView|u
400402 * @param removeIndex The index of the view to remove
401403 */
402404export function removeView ( lContainer : LContainer , removeIndex : number ) {
403- const view = lContainer [ VIEWS ] [ removeIndex ] ;
404- if ( view ) {
405- detachView ( lContainer , removeIndex ) ;
406- destroyLView ( view ) ;
407- }
405+ const detachedView = detachView ( lContainer , removeIndex ) ;
406+ detachedView && destroyLView ( detachedView ) ;
408407}
409408
410409/**
@@ -678,9 +677,8 @@ export function nativeNextSibling(renderer: Renderer3, node: RNode): RNode|null
678677function getNativeAnchorNode ( parentTNode : TNode , lView : LView ) : RNode | null {
679678 if ( parentTNode . type === TNodeType . View ) {
680679 const lContainer = getLContainer ( parentTNode as TViewNode , lView ) ! ;
681- const views = lContainer [ VIEWS ] ;
682- const index = views . indexOf ( lView ) ;
683- return getBeforeNodeForView ( index , views , lContainer [ NATIVE ] ) ;
680+ const index = lContainer . indexOf ( lView , CONTAINER_HEADER_OFFSET ) - CONTAINER_HEADER_OFFSET ;
681+ return getBeforeNodeForView ( index , lContainer ) ;
684682 } else if (
685683 parentTNode . type === TNodeType . ElementContainer ||
686684 parentTNode . type === TNodeType . IcuContainer ) {
@@ -729,9 +727,11 @@ function getHighestElementOrICUContainer(tNode: TNode): TNode {
729727 return tNode ;
730728}
731729
732- export function getBeforeNodeForView ( index : number , views : LView [ ] , containerNative : RComment ) {
733- if ( index + 1 < views . length ) {
734- const view = views [ index + 1 ] as LView ;
730+ export function getBeforeNodeForView ( index : number , lContainer : LContainer ) {
731+ const containerNative = lContainer [ NATIVE ] ;
732+
733+ if ( index + 1 < lContainer . length - CONTAINER_HEADER_OFFSET ) {
734+ const view = lContainer [ CONTAINER_HEADER_OFFSET + index + 1 ] as LView ;
735735 const viewTNode = view [ T_HOST ] as TViewNode ;
736736 return viewTNode . child ? getNativeByTNode ( viewTNode . child , view ) : containerNative ;
737737 } else {
@@ -817,9 +817,8 @@ function appendProjectedNode(
817817 // Alternatively a container is projected at the root of a component's template
818818 // and can't be re-projected (as not content of any component).
819819 // Assign the final projection location in those cases.
820- const views = nodeOrContainer [ VIEWS ] ;
821- for ( let i = 0 ; i < views . length ; i ++ ) {
822- addRemoveViewFromContainer ( views [ i ] , true , nodeOrContainer [ NATIVE ] ) ;
820+ for ( let i = CONTAINER_HEADER_OFFSET ; i < nodeOrContainer . length ; i ++ ) {
821+ addRemoveViewFromContainer ( nodeOrContainer [ i ] , true , nodeOrContainer [ NATIVE ] ) ;
823822 }
824823 } else {
825824 if ( projectedTNode . type === TNodeType . ElementContainer ) {
0 commit comments