Skip to content

Commit e15b6a9

Browse files
c42fandyferris
authored andcommitted
Define size more explicitly, helping the compiler
1 parent 2a09e2c commit e15b6a9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/abstractarray.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
length(a::SA) where {SA <: StaticArray} = prod(Size(SA))
22
length(a::Type{SA}) where {SA <: StaticArray} = prod(Size(SA))
33

4-
size(::StaticArray{S}) where {S} = get(Size(S))
5-
@pure size(::Type{<:StaticArray{S}}) where {S} = get(Size(S))
6-
7-
size(::SA, d::Int) where {SA <: StaticArray} = Size(SA)[d]
8-
@pure size(::Type{SA}, d::Int) where {SA <: StaticArray} = Size(SA)[d]
4+
@pure size(::Type{<:StaticArray{S}}) where S = tuple(S.parameters...)
5+
@inline function size(t::Type{<:StaticArray}, d::Int)
6+
S = size(t)
7+
d > length(S) ? 1 : S[d]
8+
end
9+
@inline size(a::StaticArray) = size(typeof(a))
10+
@inline size(a::StaticArray, d::Int) = size(typeof(a), d)
911

1012
# This seems to confuse Julia a bit in certain circumstances (specifically for trailing 1's)
1113
@inline function Base.isassigned(a::StaticArray, i::Int...)

0 commit comments

Comments
 (0)