Skip to content

Commit 40fa4b0

Browse files
rfourquetvtjnash
andauthored
Update base/array.jl
Co-authored-by: Jameson Nash <[email protected]>
1 parent 82dd7d6 commit 40fa4b0

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

base/array.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,21 +1306,20 @@ julia> keepat!([6, 5, 4, 3, 2, 1], 1:2:5)
13061306
2
13071307
```
13081308
"""
1309-
function keepat!(a::Vector, inds)
1310-
n = length(a)
1311-
l = 0
1312-
i = 1
1309+
function keepat!(a::AbstractVector, inds)
1310+
isempty(inds) && return a
1311+
local prev
1312+
i = firstindex(a)
13131313
for k in inds
1314-
1 <= k <= n || throw(BoundsError(a, k))
1315-
l < k || throw(ArgumentError("indices must be unique and sorted"))
1314+
@isdefined(prev) && (prev <= k || throw(ArgumentError("indices must be sorted")))
13161315
if i != k
1317-
@inbounds a[i] = a[k]
1316+
a[i] = a[k]
13181317
end
1319-
l = k
1320-
i += 1
1318+
prev = k
1319+
i = nextind(a, i)
13211320
end
1322-
_deleteend!(a, n-i+1)
1323-
a
1321+
deleteat!(a, i:lastindex(a))
1322+
return a
13241323
end
13251324

13261325
"""

0 commit comments

Comments
 (0)