Skip to content

Commit 2e865dd

Browse files
giordanonsajko
andauthored
Use linear indexing (#6)
Suggested-by: Neven Sajko <[email protected]> Co-authored-by: Neven Sajko <[email protected]>
1 parent f8b71ff commit 2e865dd

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/FixedSizeArrays.jl

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,9 @@ function (self::Type{FixedSizeArray{T,N}})(::UndefInitializer, size::Vararg{Int,
1414
return FixedSizeArray(Memory{T}(undef, prod(size)), size)
1515
end
1616

17-
Base.@propagate_inbounds function Base.setindex!(A::FixedSizeArray{T}, x, i::Int) where {T}
18-
getfield(A, :mem)[i] = x
19-
return A
20-
end
21-
Base.@inline function Base.setindex!(A::FixedSizeArray{T}, x, i1::Int, i2::Int, I::Int...) where {T}
22-
@boundscheck checkbounds(A, i1, i2, I...) # generally _to_linear_index requires bounds checking
23-
getfield(A, :mem)[Base._to_linear_index(A, i1, i2, I...)] = x
24-
return A
25-
end
26-
Base.@propagate_inbounds function Base.getindex(A::FixedSizeArray, i::Int)
27-
getfield(A, :mem)[i]
28-
end
29-
function Base.getindex(A::FixedSizeArray, i1::Int, i2::Int, I::Int...)
30-
@inline
31-
@boundscheck checkbounds(A, i1, i2, I...) # generally _to_linear_index requires bounds checking
32-
return @inbounds A[Base._to_linear_index(A, i1, i2, I...)]
33-
end
17+
Base.IndexStyle(::Type{<:FixedSizeArray}) = IndexLinear()
18+
Base.@propagate_inbounds Base.getindex(A::FixedSizeArray, i::Int) = A.mem[i]
19+
Base.@propagate_inbounds Base.setindex!(A::FixedSizeArray, v, i::Int) = A.mem[i] = v
3420

3521
Base.size(a::FixedSizeArray) = getfield(a, :size)
3622

0 commit comments

Comments
 (0)