@@ -32,15 +32,13 @@ export abstract class TypedArray<T,V> {
32
32
33
33
@inline
34
34
get length ( ) : i32 {
35
- return ( this . byteLength - this . byteOffset ) >> alignof < T > ( ) ;
35
+ return this . byteLength > >> alignof < T > ( ) ;
36
36
}
37
37
38
38
@operator ( "[]" )
39
39
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 ) ;
44
42
}
45
43
46
44
@inline @operator ( "{}" )
@@ -50,10 +48,8 @@ export abstract class TypedArray<T,V> {
50
48
51
49
@operator ( "[]=" )
52
50
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 ) ;
57
53
}
58
54
59
55
@inline @operator ( "{}=" )
@@ -95,7 +91,7 @@ export abstract class TypedArray<T,V> {
95
91
var slice = memory . allocate ( offsetof < this> ( ) ) ;
96
92
store < usize > ( slice , this . buffer , offsetof < this> ( "buffer" ) ) ;
97
93
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" ) ) ;
99
95
return changetype < this> ( slice ) ;
100
96
}
101
97
0 commit comments