@@ -225,19 +225,28 @@ class RenderViewBuilder<N> implements RenderCommandVisitor {
225225 componentTemplate : RenderComponentTemplate ) : N {
226226 var el : N = context . consumeInplaceElement ( ) ;
227227 var attrNameAndValues = cmd . attrNameAndValues ;
228- if ( this . template . encapsulation === ViewEncapsulation . Emulated ) {
228+ var templateEmulatedEncapsulation = this . template . encapsulation === ViewEncapsulation . Emulated ;
229+ var componentEmulatedEncapsulation =
230+ isPresent ( componentTemplate ) &&
231+ componentTemplate . encapsulation === ViewEncapsulation . Emulated ;
232+ var newAttrLength = attrNameAndValues . length + ( templateEmulatedEncapsulation ? 2 : 0 ) +
233+ ( componentEmulatedEncapsulation ? 2 : 0 ) ;
234+ if ( newAttrLength > attrNameAndValues . length ) {
229235 // Note: Need to clone attrNameAndValues to make it writable!
230- if ( isPresent ( componentTemplate ) ) {
231- attrNameAndValues = attrNameAndValues . concat ( [
232- _shimContentAttribute ( this . template . shortId ) ,
233- '' ,
234- _shimHostAttribute ( componentTemplate . shortId ) ,
235- ''
236- ] ) ;
237- } else {
238- attrNameAndValues =
239- attrNameAndValues . concat ( [ _shimContentAttribute ( this . template . shortId ) , '' ] ) ;
236+ var newAttrNameAndValues = ListWrapper . createFixedSize ( newAttrLength ) ;
237+ var attrIndex ;
238+ for ( attrIndex = 0 ; attrIndex < attrNameAndValues . length ; attrIndex ++ ) {
239+ newAttrNameAndValues [ attrIndex ] = attrNameAndValues [ attrIndex ] ;
240+ }
241+ if ( templateEmulatedEncapsulation ) {
242+ newAttrNameAndValues [ attrIndex ++ ] = _shimContentAttribute ( this . template . shortId ) ;
243+ newAttrNameAndValues [ attrIndex ++ ] = '' ;
244+ }
245+ if ( componentEmulatedEncapsulation ) {
246+ newAttrNameAndValues [ attrIndex ++ ] = _shimHostAttribute ( componentTemplate . shortId ) ;
247+ newAttrNameAndValues [ attrIndex ++ ] = '' ;
240248 }
249+ attrNameAndValues = newAttrNameAndValues ;
241250 }
242251 if ( isPresent ( el ) ) {
243252 context . factory . mergeElement ( el , attrNameAndValues ) ;
0 commit comments