@@ -3,36 +3,28 @@ module FixedSizeArrays
3
3
export FixedSizeArray, FixedSizeVector, FixedSizeMatrix
4
4
5
5
mutable struct FixedSizeArray{T,N} <: DenseArray{T,N}
6
- ref :: MemoryRef {T}
6
+ mem :: Memory {T}
7
7
const size:: NTuple{N,Int}
8
8
end
9
9
10
10
const FixedSizeVector{T} = FixedSizeArray{T,1 }
11
11
const FixedSizeMatrix{T} = FixedSizeArray{T,2 }
12
12
13
- eval (:(function (self:: Type{FixedSizeArray{T,N}} )(:: UndefInitializer , size:: Vararg{Int,N} ) where {T,N}
14
- mem = fieldtype (fieldtype (self, :ref ), :mem )(undef, prod (size))
15
- return $ (Expr (:new , :self , :(Core. memoryref (mem)), :(size)))
16
- end ))
13
+ function (self:: Type{FixedSizeArray{T,N}} )(:: UndefInitializer , size:: Vararg{Int,N} ) where {T,N}
14
+ return FixedSizeArray (Memory {T} (undef, prod (size)), size)
15
+ end
17
16
18
- function Base. setindex! (A:: FixedSizeArray{T} , x, i:: Int ) where {T}
19
- Base. @_noub_if_noinbounds_meta
20
- @boundscheck (i - 1 )% UInt < length (A)% UInt || throw_boundserror (A, (i,))
21
- Core. memoryrefset! (Core. memoryref (A. ref, i, false ), x isa T ? x : convert (T,x):: T , :not_atomic , false )
17
+ Base. @propagate_inbounds function Base. setindex! (A:: FixedSizeArray{T} , x, i:: Int ) where {T}
18
+ getfield (A, :mem )[i] = x
22
19
return A
23
20
end
24
- function Base. setindex! (A:: FixedSizeArray{T} , x, i1:: Int , i2:: Int , I:: Int... ) where {T}
25
- @inline
26
- Base. @_noub_if_noinbounds_meta
21
+ Base. @inline function Base. setindex! (A:: FixedSizeArray{T} , x, i1:: Int , i2:: Int , I:: Int... ) where {T}
27
22
@boundscheck checkbounds (A, i1, i2, I... ) # generally _to_linear_index requires bounds checking
28
- Core . memoryrefset! (Core . memoryref (A . ref, Base. _to_linear_index (A, i1, i2, I... ), false ), x isa T ? x : convert (T,x) :: T , :not_atomic , false )
23
+ getfield (A, :mem )[ Base. _to_linear_index (A, i1, i2, I... )] = x
29
24
return A
30
25
end
31
-
32
- function Base. getindex (A:: FixedSizeArray , i:: Int )
33
- Base. @_noub_if_noinbounds_meta
34
- @boundscheck Base. ult_int (Base. bitcast (UInt, Base. sub_int (i, 1 )), Base. bitcast (UInt, length (A))) || throw_boundserror (A, (i,))
35
- Core. memoryrefget (Core. memoryref (getfield (A, :ref ), i, false ), :not_atomic , false )
26
+ Base. @propagate_inbounds function Base. getindex (A:: FixedSizeArray , i:: Int )
27
+ getfield (A, :mem )[i]
36
28
end
37
29
function Base. getindex (A:: FixedSizeArray , i1:: Int , i2:: Int , I:: Int... )
38
30
@inline
0 commit comments