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
9 changes: 8 additions & 1 deletion src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ function Base.getindex(v::MemoryView, idx::AbstractUnitRange)
isempty(idx) && return typeof(v)(unsafe, memoryref(v.ref.mem), 0)
@boundscheck checkbounds(v, idx)
newref = @inbounds memoryref(v.ref, Int(first(idx))::Int)
return typeof(v)(unsafe, newref, length(idx))
return typeof(v)(unsafe, newref, Int(length(idx))::Int)
end

function Base.getindex(v::MemoryView, idx::UnitRange{UInt})
isempty(idx) && return typeof(v)(unsafe, memoryref(v.ref.mem), 0)
@boundscheck checkbounds(v, idx)
newref = @inbounds memoryref(v.ref, first(idx) % Int)
return typeof(v)(unsafe, newref, length(idx) % Int)
end

# Faster method, because we don't need to create a new memoryref, and also don't
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ end

@test_throws BoundsError mem[Base.OneTo(8)]
@test_throws BoundsError mem[Base.OneTo(typemax(Int))]

# UInt indexing
v = MemoryView([3, 4, 5, 6, 7])
v2 = v[UInt(2):UInt(4)]
@test v2 == 4:6
@test isempty(v2[UInt(2):UInt(1)])
@test isempty(v2[UInt(6):UInt(5)])
end

@testset "Views of memviews" begin
Expand Down
Loading