Skip to content

Commit

Permalink
Reduce invalidation by not specializing lastindex/axes1 (#311)
Browse files Browse the repository at this point in the history
* don't specialize firstindex/lastindex

* bump version to v1.12.8

* don't specialize axes1 for IdOffsetRange
  • Loading branch information
jishnub committed Oct 12, 2022
1 parent b845230 commit 9c3b73f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "OffsetArrays"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.12.7"
version = "1.12.8"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
15 changes: 10 additions & 5 deletions src/axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ offset_coerce(::Type{I}, r::AbstractUnitRange) where I<:AbstractUnitRange =
convert(I, r)::I, 0

@inline Base.parent(r::IdOffsetRange) = r.parent
@inline Base.axes(r::IdOffsetRange) = (Base.axes1(r),)
@inline Base.axes1(r::IdOffsetRange) = IdOffsetRange(Base.axes1(r.parent), r.offset)
@inline Base.unsafe_indices(r::IdOffsetRange) = (Base.axes1(r),)
@inline Base.axes(r::IdOffsetRange) = (axes1(r),)
@inline axes1(r::IdOffsetRange) = IdOffsetRange(Base.axes1(r.parent), r.offset)
if VERSION < v"1.8.2"
Base.axes1(r::IdOffsetRange) = axes1(r)
end
@inline Base.unsafe_indices(r::IdOffsetRange) = (axes1(r),)
@inline Base.length(r::IdOffsetRange) = length(r.parent)
@inline Base.isempty(r::IdOffsetRange) = isempty(r.parent)
#= We specialize on reduced_indices to work around cases where the parent axis type doesn't
Expand All @@ -188,8 +191,10 @@ end
Base.reduced_index(i::IdOffsetRange) = typeof(i)(first(i):first(i))
# Workaround for #92 on Julia < 1.4
Base.reduced_index(i::IdentityUnitRange{<:IdOffsetRange}) = typeof(i)(first(i):first(i))
for f in [:firstindex, :lastindex]
@eval @inline Base.$f(r::IdOffsetRange) = $f(r.parent) + r.offset
if VERSION < v"1.8.2"
for f in [:firstindex, :lastindex]
@eval @inline Base.$f(r::IdOffsetRange) = $f(r.parent) + r.offset
end
end
for f in [:first, :last]
# coerce the type to deal with values that get promoted on addition (eg. Bool)
Expand Down

2 comments on commit 9c3b73f

@jishnub
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/70002

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 v1.12.8 -m "<description of version>" 9c3b73fe160a8e9f94b058ed7bb585cb3fe68409
git push origin v1.12.8

Please sign in to comment.