@@ -11,6 +11,8 @@ import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
1111import  { TemplateLoader }  from  'core/compiler/template_loader' ; 
1212
1313import  { reflector }  from  'reflection/reflection' ; 
14+ import  { DOM ,  document ,  Element }  from  'facade/dom' ; 
15+ import  { isPresent }  from  'facade/lang' ; 
1416
1517var  MAX_DEPTH  =  9 ; 
1618
@@ -146,6 +148,28 @@ export function main() {
146148    } ) ; 
147149
148150  } ) ; 
151+ 
152+   benchmark ( `baseline tree benchmark` ,  function ( )  { 
153+     var  baselineAppElement  =  DOM . querySelectorAll ( document ,  'baseline' ) [ 0 ] ; 
154+     var  rootTreeComponent  =  new  BaseLineTreeComponent ( ) ; 
155+     DOM . appendChild ( baselineAppElement ,  rootTreeComponent . element ) ; 
156+ 
157+     var  count  =  0 ; 
158+ 
159+     benchmarkStep ( `destroyDom binary tree of depth ${ MAX_DEPTH }  ` ,  function ( )  { 
160+       rootTreeComponent . update ( new  TreeNode ( '' ,  null ,  null ) ) ; 
161+     } ) ; 
162+ 
163+     benchmarkStep ( `createDom binary tree of depth ${ MAX_DEPTH }  ` ,  function ( )  { 
164+       var  maxDepth  =  9 ; 
165+       var  values  =  count ++  %  2  ==  0  ?
166+         [ '0' ,  '1' ,  '2' ,  '3' ,  '4' ,  '5' ,  '6' ,  '7' ,  '8' ,  '9' ,  '*' ]  :
167+         [ 'A' ,  'B' ,  'C' ,  'D' ,  'E' ,  'F' ,  'G' ,  'H' ,  'I' ,  'J' ,  '-' ] ; 
168+ 
169+       rootTreeComponent . update ( buildTree ( maxDepth ,  values ,  0 ) ) ; 
170+     } ) ; 
171+ 
172+   } ) ; 
149173} 
150174
151175class  TreeNode  { 
@@ -167,6 +191,78 @@ function buildTree(maxDepth, values, curDepth) {
167191      buildTree ( maxDepth ,  values ,  curDepth + 1 ) ) ; 
168192} 
169193
194+ var  BASELINE_TEMPLATE  =  DOM . createTemplate ( ` 
195+     <span> {{}} 
196+        <template class="ng-binding"></template> 
197+        <template class="ng-binding"></template> 
198+     </span>` ) ; 
199+ 
200+ 
201+ class  BaseLineTreeComponent  { 
202+   element :Element ; 
203+   value :BaseLineInterpolation ; 
204+   left :BaseLineIf ; 
205+   right :BaseLineIf ; 
206+   constructor ( )  { 
207+     this . element  =  DOM . createElement ( 'span' ) ; 
208+     var  clone  =  DOM . clone ( BASELINE_TEMPLATE . content . children [ 0 ] ) ; 
209+     var  shadowRoot  =  this . element . createShadowRoot ( ) ; 
210+     DOM . appendChild ( shadowRoot ,  clone ) ; 
211+ 
212+     this . value  =  new  BaseLineInterpolation ( clone . childNodes [ 0 ] ) ; 
213+     this . left  =  new  BaseLineIf ( clone . children [ 0 ] ) ; 
214+     this . right  =  new  BaseLineIf ( clone . children [ 1 ] ) ; 
215+   } 
216+   update ( value :TreeNode )  { 
217+     this . value . update ( value . value ) ; 
218+     this . left . update ( value . left ) ; 
219+     this . right . update ( value . right ) ; 
220+   } 
221+ } 
222+ 
223+ class  BaseLineInterpolation  { 
224+   value :string ; 
225+   textNode ; 
226+   constructor ( textNode )  { 
227+     this . value  =  null ; 
228+     this . textNode  =  textNode ; 
229+   } 
230+   update ( value :string )  { 
231+     if  ( this . value  !==  value )  { 
232+       this . value  =  value ; 
233+       DOM . setText ( this . textNode ,  value  +  ' ' ) ; 
234+     } 
235+   } 
236+ } 
237+ 
238+ class  BaseLineIf  { 
239+   condition :boolean ; 
240+   component :BaseLineTreeComponent ; 
241+   anchor :Element ; 
242+   constructor ( anchor )  { 
243+     this . anchor  =  anchor ; 
244+     this . condition  =  false ; 
245+     this . component  =  null ; 
246+   } 
247+   update ( value :TreeNode )  { 
248+     var  newCondition  =  isPresent ( value ) ; 
249+     if  ( this . condition  !==  newCondition )  { 
250+       this . condition  =  newCondition ; 
251+       if  ( isPresent ( this . component ) )  { 
252+         this . component . element . remove ( ) ; 
253+         this . component  =  null ; 
254+       } 
255+       if  ( this . condition )  { 
256+         this . component  =  new  BaseLineTreeComponent ( ) ; 
257+         this . anchor . parentNode . insertBefore ( this . component . element ,  this . anchor ) ; 
258+       } 
259+     } 
260+     if  ( isPresent ( this . component ) )  { 
261+       this . component . update ( value ) ; 
262+     } 
263+   } 
264+ } 
265+ 
170266class  AppComponent  { 
171267  initData :TreeNode ; 
172268  constructor ( )  { 
0 commit comments