Skip to content

Commit 22a593a

Browse files
committed
generic size: avoid method static parameters and abstract type assert
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. These seems like they might potentially cause regressions
1 parent cdd4ac5 commit 22a593a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

base/abstractarray.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ julia> size(A, 2)
3939
3
4040
```
4141
"""
42-
size(t::AbstractArray{T,N}, d) where {T,N} = d::Integer <= N ? size(t)[d] : 1
42+
function size(t::AbstractArray, d)
43+
function f(t::Tuple, d::Integer)
44+
d <= length(t) ? t[d] : 1
45+
end
46+
sz = size(t)
47+
@inline f(sz, d)
48+
end
4349

4450
"""
4551
axes(A, d)

0 commit comments

Comments
 (0)