11/// <reference path="./rt/index.d.ts" />
22
33import { BLOCK_MAXSIZE } from "./rt/common" ;
4+ import { Runtime } from "shared/runtime" ;
45import { COMPARATOR , SORT } from "./util/sort" ;
56import { REVERSE } from "./util/bytes" ;
67import { joinBooleanArray , joinIntegerArray , joinFloatArray , joinStringArray , joinReferenceArray } from "./util/string" ;
@@ -22,7 +23,11 @@ function ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: b
2223 let newCapacity = max ( newSize , MIN_SIZE ) << alignLog2 ;
2324 if ( canGrow ) newCapacity = max ( min ( oldCapacity << 1 , BLOCK_MAXSIZE ) , newCapacity ) ;
2425 let newData = __renew ( oldData , newCapacity ) ;
25- memory . fill ( newData + oldCapacity , 0 , newCapacity - oldCapacity ) ;
26+ // __new / __renew already init memory range as zeros in Incremental runtime.
27+ // So try to avoid this.
28+ if ( ASC_RUNTIME != Runtime . Incremental ) {
29+ memory . fill ( newData + oldCapacity , 0 , newCapacity - oldCapacity ) ;
30+ }
2631 if ( newData !== oldData ) { // oldData has been free'd
2732 store < usize > ( array , newData , offsetof < ArrayBufferView > ( "buffer" ) ) ;
2833 store < usize > ( array , newData , offsetof < ArrayBufferView > ( "dataStart" ) ) ;
@@ -66,7 +71,9 @@ export class Array<T> {
6671 // reserve capacity for at least MIN_SIZE elements
6772 var bufferSize = max ( < usize > length , MIN_SIZE ) << alignof < T > ( ) ;
6873 var buffer = changetype < ArrayBuffer > ( __new ( bufferSize , idof < ArrayBuffer > ( ) ) ) ;
69- memory . fill ( changetype < usize > ( buffer ) , 0 , bufferSize ) ;
74+ if ( ASC_RUNTIME != Runtime . Incremental ) {
75+ memory . fill ( changetype < usize > ( buffer ) , 0 , bufferSize ) ;
76+ }
7077 this . buffer = buffer ; // links
7178 this . dataStart = changetype < usize > ( buffer ) ;
7279 this . byteLength = < i32 > bufferSize ;
0 commit comments