@@ -352,32 +352,23 @@ has_offset_axes(a::ReinterpretArray) = has_offset_axes(a.parent)
352352elsize (:: Type{<:ReinterpretArray{T}} ) where {T} = sizeof (T)
353353cconvert (:: Type{Ptr{T}} , a:: ReinterpretArray{T,N,S} where N) where {T,S} = cconvert (Ptr{S}, a. parent)
354354
355- @propagate_inbounds function getindex (a:: NonReshapedReinterpretArray{T,0,S} ) where {T,S}
355+ @inline @ propagate_inbounds function getindex (a:: NonReshapedReinterpretArray{T,0,S} ) where {T,S}
356356 if isprimitivetype (T) && isprimitivetype (S)
357357 reinterpret (T, a. parent[])
358358 else
359359 a[firstindex (a)]
360360 end
361361end
362362
363- check_ptr_indexable (a:: ReinterpretArray , sz = elsize (a)) = check_ptr_indexable (parent (a), sz)
364- check_ptr_indexable (a:: ReshapedArray , sz) = check_ptr_indexable (parent (a), sz)
365- check_ptr_indexable (a:: FastContiguousSubArray , sz) = check_ptr_indexable (parent (a), sz)
366- check_ptr_indexable (a:: Array , sz) = sizeof (eltype (a)) != = sz
367- check_ptr_indexable (a:: Memory , sz) = true
368- check_ptr_indexable (a:: AbstractArray , sz) = false
363+ @inline @propagate_inbounds getindex (a:: ReinterpretArray ) = a[firstindex (a)]
369364
370- @propagate_inbounds getindex (a:: ReinterpretArray ) = a[firstindex (a)]
371-
372- @propagate_inbounds function getindex (a:: ReinterpretArray{T,N,S} , inds:: Vararg{Int, N} ) where {T,N,S}
365+ @inline @propagate_inbounds function getindex (a:: ReinterpretArray{T,N,S} , inds:: Vararg{Int, N} ) where {T,N,S}
373366 check_readable (a)
374- check_ptr_indexable (a) && return _getindex_ptr (a, inds... )
375367 _getindex_ra (a, inds[1 ], tail (inds))
376368end
377369
378- @propagate_inbounds function getindex (a:: ReinterpretArray{T,N,S} , i:: Int ) where {T,N,S}
370+ @inline @ propagate_inbounds function getindex (a:: ReinterpretArray{T,N,S} , i:: Int ) where {T,N,S}
379371 check_readable (a)
380- check_ptr_indexable (a) && return _getindex_ptr (a, i)
381372 if isa (IndexStyle (a), IndexLinear)
382373 return _getindex_ra (a, i, ())
383374 end
@@ -387,22 +378,16 @@ end
387378 isempty (inds) ? _getindex_ra (a, 1 , ()) : _getindex_ra (a, inds[1 ], tail (inds))
388379end
389380
390- @propagate_inbounds function getindex (a:: ReshapedReinterpretArray{T,N,S} , ind:: SCartesianIndex2 ) where {T,N,S}
381+ @inline @ propagate_inbounds function getindex (a:: ReshapedReinterpretArray{T,N,S} , ind:: SCartesianIndex2 ) where {T,N,S}
391382 check_readable (a)
392383 s = Ref {S} (a. parent[ind. j])
393- tptr = Ptr {T} (unsafe_convert (Ref{S}, s))
394- GC. @preserve s return unsafe_load (tptr, ind. i)
395- end
396-
397- @inline function _getindex_ptr (a:: ReinterpretArray{T} , inds... ) where {T}
398- @boundscheck checkbounds (a, inds... )
399- li = _to_linear_index (a, inds... )
400- ap = cconvert (Ptr{T}, a)
401- p = unsafe_convert (Ptr{T}, ap) + sizeof (T) * (li - 1 )
402- GC. @preserve ap return unsafe_load (p)
384+ GC. @preserve s begin
385+ tptr = Ptr {T} (unsafe_convert (Ref{S}, s))
386+ return unsafe_load (tptr, ind. i)
387+ end
403388end
404389
405- @propagate_inbounds function _getindex_ra (a:: NonReshapedReinterpretArray{T,N,S} , i1:: Int , tailinds:: TT ) where {T,N,S,TT}
390+ @inline @ propagate_inbounds function _getindex_ra (a:: NonReshapedReinterpretArray{T,N,S} , i1:: Int , tailinds:: TT ) where {T,N,S,TT}
406391 # Make sure to match the scalar reinterpret if that is applicable
407392 if sizeof (T) == sizeof (S) && (fieldcount (T) + fieldcount (S)) == 0
408393 if issingletontype (T) # singleton types
458443 end
459444end
460445
461- @propagate_inbounds function _getindex_ra (a:: ReshapedReinterpretArray{T,N,S} , i1:: Int , tailinds:: TT ) where {T,N,S,TT}
446+ @inline @ propagate_inbounds function _getindex_ra (a:: ReshapedReinterpretArray{T,N,S} , i1:: Int , tailinds:: TT ) where {T,N,S,TT}
462447 # Make sure to match the scalar reinterpret if that is applicable
463448 if sizeof (T) == sizeof (S) && (fieldcount (T) + fieldcount (S)) == 0
464449 if issingletontype (T) # singleton types
@@ -505,33 +490,31 @@ end
505490 end
506491end
507492
508- @propagate_inbounds function setindex! (a:: NonReshapedReinterpretArray{T,0,S} , v) where {T,S}
493+ @inline @ propagate_inbounds function setindex! (a:: NonReshapedReinterpretArray{T,0,S} , v) where {T,S}
509494 if isprimitivetype (S) && isprimitivetype (T)
510495 a. parent[] = reinterpret (S, v)
511496 return a
512497 end
513498 setindex! (a, v, firstindex (a))
514499end
515500
516- @propagate_inbounds setindex! (a:: ReinterpretArray , v) = setindex! (a, v, firstindex (a))
501+ @inline @ propagate_inbounds setindex! (a:: ReinterpretArray , v) = setindex! (a, v, firstindex (a))
517502
518- @propagate_inbounds function setindex! (a:: ReinterpretArray{T,N,S} , v, inds:: Vararg{Int, N} ) where {T,N,S}
503+ @inline @ propagate_inbounds function setindex! (a:: ReinterpretArray{T,N,S} , v, inds:: Vararg{Int, N} ) where {T,N,S}
519504 check_writable (a)
520- check_ptr_indexable (a) && return _setindex_ptr! (a, v, inds... )
521505 _setindex_ra! (a, v, inds[1 ], tail (inds))
522506end
523507
524- @propagate_inbounds function setindex! (a:: ReinterpretArray{T,N,S} , v, i:: Int ) where {T,N,S}
508+ @inline @ propagate_inbounds function setindex! (a:: ReinterpretArray{T,N,S} , v, i:: Int ) where {T,N,S}
525509 check_writable (a)
526- check_ptr_indexable (a) && return _setindex_ptr! (a, v, i)
527510 if isa (IndexStyle (a), IndexLinear)
528511 return _setindex_ra! (a, v, i, ())
529512 end
530513 inds = _to_subscript_indices (a, i)
531514 _setindex_ra! (a, v, inds[1 ], tail (inds))
532515end
533516
534- @propagate_inbounds function setindex! (a:: ReshapedReinterpretArray{T,N,S} , v, ind:: SCartesianIndex2 ) where {T,N,S}
517+ @inline @ propagate_inbounds function setindex! (a:: ReshapedReinterpretArray{T,N,S} , v, ind:: SCartesianIndex2 ) where {T,N,S}
535518 check_writable (a)
536519 v = convert (T, v):: T
537520 s = Ref {S} (a. parent[ind. j])
543526 return a
544527end
545528
546- @inline function _setindex_ptr! (a:: ReinterpretArray{T} , v, inds... ) where {T}
547- @boundscheck checkbounds (a, inds... )
548- li = _to_linear_index (a, inds... )
549- ap = cconvert (Ptr{T}, a)
550- p = unsafe_convert (Ptr{T}, ap) + sizeof (T) * (li - 1 )
551- GC. @preserve ap unsafe_store! (p, v)
552- return a
553- end
554-
555- @propagate_inbounds function _setindex_ra! (a:: NonReshapedReinterpretArray{T,N,S} , v, i1:: Int , tailinds:: TT ) where {T,N,S,TT}
529+ @inline @propagate_inbounds function _setindex_ra! (a:: NonReshapedReinterpretArray{T,N,S} , v, i1:: Int , tailinds:: TT ) where {T,N,S,TT}
556530 v = convert (T, v):: T
557531 # Make sure to match the scalar reinterpret if that is applicable
558532 if sizeof (T) == sizeof (S) && (fieldcount (T) + fieldcount (S)) == 0
625599 return a
626600end
627601
628- @propagate_inbounds function _setindex_ra! (a:: ReshapedReinterpretArray{T,N,S} , v, i1:: Int , tailinds:: TT ) where {T,N,S,TT}
602+ @inline @ propagate_inbounds function _setindex_ra! (a:: ReshapedReinterpretArray{T,N,S} , v, i1:: Int , tailinds:: TT ) where {T,N,S,TT}
629603 v = convert (T, v):: T
630604 # Make sure to match the scalar reinterpret if that is applicable
631605 if sizeof (T) == sizeof (S) && (fieldcount (T) + fieldcount (S)) == 0
0 commit comments