Skip to content

Commit f87ad0c

Browse files
authored
Fix blocks in popfirst (#344)
1 parent ac4df2a commit f87ad0c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.16.39"
3+
version = "0.16.40"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/blockdeque.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,12 @@ function Base.popfirst!(A::BlockVector)
307307
isempty(A) && throw(Argument("array must be nonempty"))
308308
_squash_firsts!(A)
309309
x = popfirst!(A.blocks[1])
310-
ax, = A.axes
310+
lasts = blocklasts(A.axes[1])
311311
if isempty(A.blocks[1])
312312
popfirst!(A.blocks)
313-
popfirst!(blocklasts(ax))
314-
else
315-
blocklasts(ax)[1] -= 1
313+
popfirst!(lasts)
316314
end
315+
lasts .-= 1
317316
return x
318317
end
319318

test/test_blockdeque.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ using BlockArrays, Test
165165
@test pop!(B) == 6
166166
@test B == 1:5
167167
@test !any(isempty, blocks(B))
168+
@test blocksizes(B,1) == [1,2,2]
168169
end
169170
end
170171

@@ -176,5 +177,18 @@ using BlockArrays, Test
176177
end
177178
@test A == []
178179
@test B == 1:5
180+
181+
A = BlockArray([1:6;], [2,2,2])
182+
@test popfirst!(A) == 1
183+
@test A == 2:6
184+
@test blocksizes(A,1) == [1,2,2]
185+
186+
@testset "empty blocks" begin
187+
B = BlockArray([1:6;], [0,0,1,2,3])
188+
@test popfirst!(B) == 1
189+
@test B == 2:6
190+
@test blocksizes(B,1) == [2,3]
191+
@test !any(isempty, blocks(B))
192+
end
179193
end
180194
end

0 commit comments

Comments
 (0)