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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "MemoryViews"
uuid = "a791c907-b98b-4e44-8f4d-e4c2362c6b2f"
version = "0.3.5"
version = "0.3.6"
authors = ["Jakob Nybo Nissen <jakobnybonissen@gmail.com>"]

[weakdeps]
Expand Down
11 changes: 11 additions & 0 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ function Base.copyto!(dst::MutableMemoryView{T}, src::MemoryView{T}) where {T}
return unsafe_copyto!(dst, src)
end

function Base.fill!(v::MutableMemoryView{UInt8}, x::Integer)
xT = convert(UInt8, x)::UInt8
isempty(v) && return v
GC.@preserve v @ccall memset(
pointer(v)::Ptr{Nothing},
Int32(xT)::Cint,
(length(v) % UInt)::Csize_t
)::Cvoid
return v
end

# Optimised methods that don't boundscheck
function Base.findnext(p::Function, mem::MemoryView, start::Integer)
i = Int(start)::Int
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,18 @@ end
end
end

@testset "memset" begin
@test_throws Exception fill!(ImmutableMemoryView(UInt8[1, 2, 3]), 0x02)

v = MemoryView(UInt8[1, 2, 3, 4, 5])
fill!(v, 0x03)
@test v == fill(0x03, length(v))

v = MemoryView(UInt8[])
fill!(v, 0x03)
@test isempty(v)
end

@testset "Iterators.reverse" begin
for v in Any[AbstractString["abc", "def", ""], Char['a', 'b'], UInt32[], Int16[9, 2, 1]]
mem = MemoryView(v)
Expand Down
Loading