Skip to content

Commit

Permalink
Update base/array.jl
Browse files Browse the repository at this point in the history
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
rfourquet and vtjnash authored Apr 22, 2021
1 parent 82dd7d6 commit 40fa4b0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1306,21 +1306,20 @@ julia> keepat!([6, 5, 4, 3, 2, 1], 1:2:5)
2
```
"""
function keepat!(a::Vector, inds)
n = length(a)
l = 0
i = 1
function keepat!(a::AbstractVector, inds)
isempty(inds) && return a
local prev
i = firstindex(a)
for k in inds
1 <= k <= n || throw(BoundsError(a, k))
l < k || throw(ArgumentError("indices must be unique and sorted"))
@isdefined(prev) && (prev <= k || throw(ArgumentError("indices must be sorted")))
if i != k
@inbounds a[i] = a[k]
a[i] = a[k]
end
l = k
i += 1
prev = k
i = nextind(a, i)
end
_deleteend!(a, n-i+1)
a
deleteat!(a, i:lastindex(a))
return a
end

"""
Expand Down

0 comments on commit 40fa4b0

Please sign in to comment.