Skip to content

Commit e74d9c5

Browse files
committed
Less scary bounds check skipping. Fixes #70
1 parent 7b6bd16 commit e74d9c5

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"]
4-
version = "0.9.0"
4+
version = "0.9.1"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/set_get.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Base.@propagate_inbounds Base.getindex(x::ComponentArray, idx...) = getindex(x,
3232
@inline Base.getindex(x::ComponentArray, idx::Val...) = _getindex(x, idx...)
3333

3434
# Set ComponentArray index
35-
Base.@propagate_inbounds Base.setindex!(x::ComponentArray, v, idx::FlatIdx...) = setindex!(getdata(x), v, idx...)
35+
@inline Base.setindex!(x::ComponentArray, v, idx::FlatIdx...) = setindex!(getdata(x), v, idx...)
3636
Base.@propagate_inbounds Base.setindex!(x::ComponentArray, v, ::Colon) = setindex!(getdata(x), v, :)
3737
Base.@propagate_inbounds Base.setindex!(x::ComponentArray, v, idx...) = setindex!(x, v, toval.(idx)...)
3838
@inline Base.setindex!(x::ComponentArray, v, idx::Val...) = _setindex!(x, v, idx...)
@@ -53,14 +53,14 @@ Base.@propagate_inbounds Base.setindex!(x::ComponentArray, v, idx...) = setindex
5353
axs = map(i -> i.ax, ci)
5454
axs = remove_nulls(axs...)
5555
# the index must be valid after computing `ci`
56-
:(Base.@_inline_meta; @inbounds ComponentArray(Base.maybeview(getdata(x), $inds...), $axs...))
56+
:(Base.@_inline_meta; ComponentArray(Base.maybeview(getdata(x), $inds...), $axs...))
5757
end
5858

5959
@generated function _setindex!(x::ComponentArray, v, idx...)
6060
ci = getindex.(getaxes(x), getval.(idx))
6161
inds = map(i -> i.idx, ci)
6262
# the index must be valid after computing `ci`
63-
return :(Base.@_inline_meta; @inbounds setindex!(getdata(x), v, $inds...))
63+
return :(Base.@_inline_meta; setindex!(getdata(x), v, $inds...))
6464
end
6565

6666
Base.@propagate_inbounds Base.view(x::ComponentArray, idx::ComponentArrays.FlatIdx...) = view(getdata(x), idx...)

test/runtests.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ end
157157

158158
@test getproperty(ca, Val(:a)) == ca.a
159159

160+
@test Base.to_indices(ca, (:a, :b)) == (:a, :b)
161+
@test Base.to_indices(ca, (1, 2)) == (1, 2)
162+
@test Base.to_index(ca, :a) == :a
163+
160164
#OffsetArray stuff
161165
part_ax = PartitionedAxis(2, Axis(a=1, b=2))
162166
oaca = ComponentArray(OffsetArray(collect(1:5), -1), Axis(a=0, b=ViewAxis(1:4, part_ax)))
@@ -176,9 +180,11 @@ end
176180
@test getdata(A_vec) isa Vector
177181
@test getdata(A_mat) isa Matrix
178182

179-
@test Base.to_indices(ca, (:a, :b)) == (:a, :b)
180-
@test Base.to_indices(ca, (1, 2)) == (1, 2)
181-
@test Base.to_index(ca, :a) == :a
183+
# Issue #70
184+
let
185+
ca = ComponentVector(a=1, b=2, c=3)
186+
@test_throws BoundsError ca[:a, :b]
187+
end
182188
end
183189

184190
@testset "Set" begin

0 commit comments

Comments
 (0)