Skip to content

Commit

Permalink
Bump version (#10)
Browse files Browse the repository at this point in the history
To reflect the breaking change in 83b4218
  • Loading branch information
jakobnissen authored Dec 13, 2024
1 parent febf66c commit efad7bc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changelog
This project follows semantic versioning (semver) 2.0.
Any new features, or breaking changes, will be written in this file.
Bugfixes, internal refactors, documentation improvements and style changes will
not be mentioned here, because they do not impact how the package is to be used.

## 0.3.0
### Breaking changes
* Change the bounds checking behaviour of the find* functions to match those of
`Vector`. In particular, previously, `findnext(pred, mem, -5)` would be
equivalent to searching from index 1, and similarly, `findprev(pred, mem,
lastindex(mem) + 10)` would be equialent to searching from `lastindex(mem)`.
Now, searching from an index before the first valid index throws a `BoundsError`.
Findfirst searching from `i > lastindex(mem)`, and findlast searching from
`i < 1` will still simply return `nothing`, just like searching vectors.

### Other changes
* Add optimised versions of `findprev` and `findlast`, searching bytes
* Add optimised version of `find*(iszero, bytes)` methods
* Add optimised generic `find*` methods
* Add functions `split_first`, `split_last`, `split_at` and `split_unaligned`
* Add a more correct implementation of `Base.mightalias` for memory views and
some types of arrays



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.2.2"
version = "0.3.0"
authors = ["Jakob Nybo Nissen <[email protected]>"]

[weakdeps]
Expand Down
18 changes: 17 additions & 1 deletion src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ Base.elsize(::Type{<:MemoryView{T}}) where {T} = Base.elsize(Memory{T})
Base.sizeof(x::MemoryView) = Base.elsize(typeof(x)) * length(x)
Base.strides(::MemoryView) = (1,)

function Base.mightalias(a::MemoryView, b::MemoryView)
# For two distinct element types, they can't alias
Base.mightalias(::MemoryView, ::MemoryView) = false

function Base.mightalias(a::MemoryView{T}, b::MemoryView{T}) where {T}
(isempty(a) | isempty(b)) && return false
parent(a) === parent(b) || return false
(p1, p2) = (pointer(a), pointer(b))
Expand All @@ -72,6 +75,19 @@ function Base.mightalias(a::MemoryView, b::MemoryView)
end
end

# We don't include strings here because this union is used for mightalias
# checks, which are done implicitly, and we don't want to construct memory
# views from strings implicitly, since that currently allocates.
const KNOWN_MEM_BACKED = Union{Array, Memory, ContiguousSubArray}

function Base.mightalias(a::MemoryView, b::KNOWN_MEM_BACKED)
Base.mightalias(a, ImmutableMemoryView(b))
end

function Base.mightalias(a::KNOWN_MEM_BACKED, b::MemoryView)
Base.mightalias(ImmutableMemoryView(a), b)
end

function Base.getindex(v::MemoryView, idx::AbstractUnitRange)
# This branch is necessary, because the memoryref can't point out of bounds.
# So if the user gives an empty slice that is out of bounds, the boundscheck
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ end
@test Base.mightalias(MemoryView(v), MemoryView(v2))
@test Base.mightalias(MemoryView(v), MemoryView(view(v, 7:8)))
@test !Base.mightalias(MemoryView(v1), MemoryView(view(v, 7:8)))

v1 = [1, 2, 3]
v2 = UInt[1, 2, 3]
@test !Base.mightalias(v1, v2)
@test Base.mightalias(MemoryView(v1)[2:2], v1)
@test Base.mightalias(view(v1, 2:3), MemoryView(v1))
end

# Span of views
Expand Down

2 comments on commit efad7bc

@jakobnissen
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/121321

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" efad7bc98b07195c573f446ec7f64edb58c8b1b3
git push origin v0.3.0

Please sign in to comment.