Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,20 @@ end
## MArray methods ##
####################

function getindex(v::MArray, i::Int)
Base.@_inline_meta
@propagate_inbounds function getindex(v::MArray, i::Int)
@boundscheck checkbounds(v,i)
T = eltype(v)

if isbitstype(T)
return unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), i)
end
v.data[i]
end

@inline function setindex!(v::MArray, val, i::Int)
@boundscheck if i < 1 || i > length(v)
throw(BoundsError())
end

@boundscheck checkbounds(v,i)
T = eltype(v)

if isbitstype(T)
unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i)
else
Expand Down
32 changes: 0 additions & 32 deletions src/MMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,6 @@ end
## MMatrix methods ##
#####################

@propagate_inbounds function getindex(m::MMatrix{S1,S2,T}, i::Int) where {S1,S2,T}
#@boundscheck if i < 1 || i > length(m)
# throw(BoundsError(m,i))
#end

# This is nasty... but it turns out Julia will literally copy the whole tuple to the stack otherwise!
if isbitstype(T)
unsafe_load(Base.unsafe_convert(Ptr{T}, pointer_from_objref(m)), i)
else
# Not sure about this... slow option for now...
m.data[i]
#unsafe_load(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(m.data)), i)
end
end

@propagate_inbounds setindex!(m::MMatrix{S1,S2,T}, val, i::Int) where {S1,S2,T} = setindex!(m, convert(T, val), i)
@propagate_inbounds function setindex!(m::MMatrix{S1,S2,T}, val::T, i::Int) where {S1,S2,T}
#@boundscheck if i < 1 || i > length(m)
# throw(BoundsError(m,i))
#end

if isbitstype(T)
unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(m)), val, i)
else # TODO check that this isn't crazy. Also, check it doesn't cause problems with GC...
# This one is unsafe (#27)
# unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(m.data)), pointer_from_objref(val), i)
error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.")
end

return val
end

macro MMatrix(ex)
if !isa(ex, Expr)
error("Bad input for @MMatrix")
Expand Down
22 changes: 0 additions & 22 deletions src/MVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,6 @@ const MVector{S, T} = MArray{Tuple{S}, T, 1, S}
## MVector methods ##
#####################

@propagate_inbounds function getindex(v::MVector, i::Int)
v.data[i]
end

# Mutating setindex!
@propagate_inbounds setindex!(v::MVector{S,T}, val, i::Int) where {S,T} = setindex!(v, convert(T, val), i)
@inline function setindex!(v::MVector{S,T}, val::T, i::Int) where {S,T}
@boundscheck if i < 1 || i > length(v)
throw(BoundsError())
end

if isbitstype(T)
unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), val, i)
else
# This one is unsafe (#27)
#unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i)
error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.")
end

return val
end

macro MVector(ex)
if isa(ex, Expr) && ex.head == :vect
return esc(Expr(:call, MVector{length(ex.args)}, Expr(:tuple, ex.args...)))
Expand Down
2 changes: 2 additions & 0 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ setindex!(a::StaticArray, value, i::Int) = error("setindex!(::$(typeof(a)), valu
# Note: all indexing behavior defaults to dense, linear indexing

@propagate_inbounds function getindex(a::StaticArray, inds::Int...)
@boundscheck checkbounds(a, inds...)
_getindex_scalar(Size(a), a, inds...)
end

Expand All @@ -30,6 +31,7 @@ end
end

@propagate_inbounds function setindex!(a::StaticArray, value, inds::Int...)
@boundscheck checkbounds(a, inds...)
_setindex!_scalar(Size(a), a, value, inds...)
end

Expand Down