@@ -32,15 +32,13 @@ export abstract class TypedArray<T,V> {
3232
3333 @inline
3434 get length ( ) : i32 {
35- return ( this . byteLength - this . byteOffset ) >> alignof < T > ( ) ;
35+ return this . byteLength > >> alignof < T > ( ) ;
3636 }
3737
3838 @operator ( "[]" )
3939 protected __get ( index : i32 ) : T {
40- var byteOffset = this . byteOffset ;
41- var elementLength = ( this . byteLength - byteOffset ) >>> alignof < T > ( ) ;
42- if ( < u32 > index >= < u32 > elementLength ) throw new Error ( "Index out of bounds" ) ;
43- return loadUnsafeWithOffset < T , T > ( this . buffer , index , byteOffset ) ;
40+ if ( < u32 > index >= < u32 > ( this . byteLength >>> alignof < T > ( ) ) ) throw new Error ( "Index out of bounds" ) ;
41+ return loadUnsafeWithOffset < T , T > ( this . buffer , index , this . byteOffset ) ;
4442 }
4543
4644 @inline @operator ( "{}" )
@@ -50,10 +48,8 @@ export abstract class TypedArray<T,V> {
5048
5149 @operator ( "[]=" )
5250 protected __set ( index : i32 , value : V ) : void {
53- var byteOffset = this . byteOffset ;
54- var elementLength = ( this . byteLength - byteOffset ) >>> alignof < T > ( ) ;
55- if ( < u32 > index >= < u32 > elementLength ) throw new Error ( "Index out of bounds" ) ;
56- storeUnsafeWithOffset < T , V > ( this . buffer , index , value , byteOffset ) ;
51+ if ( < u32 > index >= < u32 > ( this . byteLength >>> alignof < T > ( ) ) ) throw new Error ( "Index out of bounds" ) ;
52+ storeUnsafeWithOffset < T , V > ( this . buffer , index , value , this . byteOffset ) ;
5753 }
5854
5955 @inline @operator ( "{}=" )
@@ -95,7 +91,7 @@ export abstract class TypedArray<T,V> {
9591 var slice = memory . allocate ( offsetof < this> ( ) ) ;
9692 store < usize > ( slice , this . buffer , offsetof < this> ( "buffer" ) ) ;
9793 store < i32 > ( slice , begin << alignof < T > ( ) , offsetof < this> ( "byteOffset" ) ) ;
98- store < i32 > ( slice , end << alignof < T > ( ) , offsetof < this> ( "byteLength" ) ) ;
94+ store < i32 > ( slice , ( end - begin ) << alignof < T > ( ) , offsetof < this> ( "byteLength" ) ) ;
9995 return changetype < this> ( slice ) ;
10096 }
10197
0 commit comments