Skip to content

Commit

Permalink
make the inner constructor an internal implementation detail (#36)
Browse files Browse the repository at this point in the history
`AbstractArray` constructors that take `AbstractArray` usually copy
the input array, something that our inner constructor doesn't do. So it
seems safer to remove the inner constructor from our public API.
  • Loading branch information
nsajko authored Apr 24, 2024
1 parent 4392680 commit d374525
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/FixedSizeArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ module FixedSizeArrays

export FixedSizeArray, FixedSizeVector, FixedSizeMatrix

"""
Internal()
Implementation detail. Do not use.
"""
struct Internal end

struct FixedSizeArray{T,N} <: DenseArray{T,N}
mem::Memory{T}
size::NTuple{N,Int}
function FixedSizeArray{T,N}(mem::Memory{T}, size::NTuple{N,Int}) where {T,N}
function FixedSizeArray{T,N}(::Internal, mem::Memory{T}, size::NTuple{N,Int}) where {T,N}
new{T,N}(mem, size)
end
end
Expand All @@ -14,7 +21,7 @@ const FixedSizeVector{T} = FixedSizeArray{T,1}
const FixedSizeMatrix{T} = FixedSizeArray{T,2}

function FixedSizeArray{T,N}(::UndefInitializer, size::NTuple{N,Int}) where {T,N}
FixedSizeArray{T,N}(Memory{T}(undef, checked_dims(size)), size)
FixedSizeArray{T,N}(Internal(), Memory{T}(undef, checked_dims(size)), size)
end
function FixedSizeArray{T,N}(::UndefInitializer, size::Vararg{Int,N}) where {T,N}
FixedSizeArray{T,N}(undef, size)
Expand Down

0 comments on commit d374525

Please sign in to comment.