|
30 | 30 | function Base.parentindices(x::MemoryView) |
31 | 31 | elz = Base.elsize(x) |
32 | 32 | return if iszero(elz) |
33 | | - (1:(x.len),) |
| 33 | + offset = Int(x.ref.ptr_or_offset) |
| 34 | + ((1 + offset):(x.len + offset),) |
34 | 35 | else |
35 | 36 | byte_offset = pointer(x.ref) - pointer(x.ref.mem) |
36 | 37 | elem_offset = div(byte_offset % UInt, elz % UInt) % Int |
@@ -112,21 +113,21 @@ function Base.getindex(v::MemoryView{T, M}, idx::AbstractUnitRange) where {T, M} |
112 | 113 | isempty(idx) && return unsafe_new_memoryview(M, memoryref(v.ref.mem), 0) |
113 | 114 | @boundscheck checkbounds(v, idx) |
114 | 115 | newref = @inbounds memoryref(v.ref, Int(first(idx))::Int) |
115 | | - return typeof(v)(unsafe, newref, Int(length(idx))::Int) |
| 116 | + return unsafe_new_memoryview(M, newref, Int(length(idx))::Int) |
116 | 117 | end |
117 | 118 |
|
118 | | -function Base.getindex(v::MemoryView, idx::UnitRange{UInt}) |
119 | | - isempty(idx) && return typeof(v)(unsafe, memoryref(v.ref.mem), 0) |
| 119 | +function Base.getindex(v::MemoryView{T, M}, idx::UnitRange{UInt}) where {T, M} |
| 120 | + isempty(idx) && return unsafe_new_memoryview(M, v.ref, 0) |
120 | 121 | @boundscheck checkbounds(v, idx) |
121 | 122 | newref = @inbounds memoryref(v.ref, first(idx) % Int) |
122 | | - return typeof(v)(unsafe, newref, length(idx) % Int) |
| 123 | + return unsafe_new_memoryview(M, newref, length(idx) % Int) |
123 | 124 | end |
124 | 125 |
|
125 | 126 | # Faster method, because we don't need to create a new memoryref, and also don't |
126 | 127 | # need to handle the empty case. |
127 | | -function Base.getindex(v::MemoryView, idx::Base.OneTo) |
| 128 | +function Base.getindex(v::MemoryView{T, M}, idx::Base.OneTo) where {T, M} |
128 | 129 | @boundscheck checkbounds(v, idx) |
129 | | - return typeof(v)(unsafe, v.ref, last(idx)) |
| 130 | + return unsafe_new_memoryview(M, v.ref, last(idx)) |
130 | 131 | end |
131 | 132 |
|
132 | 133 | Base.getindex(v::MemoryView, ::Colon) = v |
|
0 commit comments