Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make parentindices return a Tuple
Browse files Browse the repository at this point in the history
Which I think it should
jakobnissen committed Jan 21, 2025
1 parent efad7bc commit 6f4784c
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/basic.jl
Original file line number Diff line number Diff line change
@@ -23,11 +23,11 @@ end
function Base.parentindices(x::MemoryView)
elz = Base.elsize(x)
if iszero(elz)
1:(x.len)
(1:(x.len),)
else
byte_offset = pointer(x.ref) - pointer(x.ref.mem)
elem_offset = div(byte_offset % UInt, elz % UInt) % Int
(elem_offset + 1):(elem_offset + x.len)
((elem_offset + 1):(elem_offset + x.len),)
end
end

6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -306,13 +306,13 @@ end

@testset "Parentindices" begin
mem = MemoryView(view(codeunits("lkdjfldfe"), 3:8))[2:6]
@test parentindices(mem) == 4:8
@test parentindices(mem) == (4:8,)

mem = MemoryView(UInt32[2, 5, 2, 1, 6, 8])[4:end]
@test parentindices(mem) == 4:6
@test parentindices(mem) == (4:6,)

mem = MemoryView(view(Vector{String}(undef, 10), 5:7))
@test parentindices(mem) == 5:7
@test parentindices(mem) == (5:7,)
end

@testset "Similar and empty" begin

0 comments on commit 6f4784c

Please sign in to comment.