Skip to content

Commit 167c0de

Browse files
authored
Merge pull request #1 from dantaras/bounds-error
Throw bounds error in pop! and popfirst!
2 parents e93c10b + 5605781 commit 167c0de

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎src/list.jl‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ end
66

77
const IntrusiveList{T} = TaggedIntrusiveList{T, :default}
88

9-
@inline function checkbounds(list::IntrusiveList)
9+
@inline function checkbounds(list::TaggedIntrusiveList)
1010
isempty(list) && throw(BoundsError(list))
1111
end
1212

@@ -67,7 +67,7 @@ function Base.push!(list::TaggedIntrusiveList{T, Tag}, node::T) where {T, Tag}
6767
end
6868

6969
function Base.pop!(list::TaggedIntrusiveList{T, Tag}) where {T, Tag}
70-
isempty(list) && throw(ArgumentError("list must be non-empty"))
70+
@boundscheck checkbounds(list)
7171
head = list.head::T
7272
tail = getprev(head, Val{Tag}())::T
7373
if circlist_unlink!(tail, Val{Tag}()) === tail
@@ -87,7 +87,7 @@ function Base.pushfirst!(list::TaggedIntrusiveList{T, Tag}, node::T) where {T, T
8787
end
8888

8989
function Base.popfirst!(list::TaggedIntrusiveList{T, Tag}) where {T, Tag}
90-
isempty(list) && throw(ArgumentError("list must be non-empty"))
90+
@boundscheck checkbounds(list)
9191
head = list.head::T
9292
new_head = circlist_unlink!(head, Val{Tag}())
9393
list.head = head === new_head ? nothing : new_head

‎src/slist.jl‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ end
66

77
const IntrusiveSList{T} = TaggedIntrusiveSList{T, :default}
88

9-
@inline function checkbounds(list::IntrusiveSList)
9+
@inline function checkbounds(list::TaggedIntrusiveSList)
1010
isempty(list) && throw(BoundsError(list))
1111
end
1212

@@ -76,7 +76,7 @@ function Base.push!(list::TaggedIntrusiveSList{T, Tag}, node::T) where {T, Tag}
7676
end
7777

7878
function Base.pop!(list::TaggedIntrusiveSList{T, Tag}) where {T, Tag}
79-
isempty(list) && throw(ArgumentError("slist must be non-empty"))
79+
@boundscheck checkbounds(list)
8080
tail = list.tail::T
8181
head = getnext(tail, Val{Tag}())::T
8282
if head === tail
@@ -103,7 +103,7 @@ function Base.pushfirst!(list::TaggedIntrusiveSList{T, Tag}, node::T) where {T,
103103
end
104104

105105
function Base.popfirst!(list::TaggedIntrusiveSList{T, Tag}) where {T, Tag}
106-
isempty(list) && throw(ArgumentError("slist must be non-empty"))
106+
@boundscheck checkbounds(list)
107107
tail = list.tail::T
108108
head = getnext(tail, Val{Tag}())::T
109109
if head === tail

‎test/list_tests.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ list_types = [
5959
@test all([x for x in list] .=== [n1])
6060
@test pop!(list) === n1
6161
@test isempty(list)
62-
@test_throws ArgumentError pop!(list)
62+
@test_throws BoundsError pop!(list)
6363
end
6464

6565
@testset "empty $ListType" for ListType in list_types

0 commit comments

Comments
 (0)