Skip to content

Commit

Permalink
reuse wrapper functions rather than ccalling directly to jl_array_del…
Browse files Browse the repository at this point in the history
…_*/jl_array_grow_* (JuliaLang#26667)
  • Loading branch information
jrevels committed Mar 31, 2018
1 parent fd4546d commit b302238
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ julia> a[1:6]
function resize!(a::Vector, nl::Integer)
l = length(a)
if nl > l
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), a, nl-l)
_growend!(a, nl-l)
elseif nl != l
if nl < 0
throw(ArgumentError("new length must be ≥ 0"))
Expand Down
28 changes: 14 additions & 14 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ function push!(B::BitVector, item)

l = _mod64(length(B))
if l == 0
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, 1)
_growend!(Bc, 1)
Bc[end] = UInt64(0)
end
B.len += 1
Expand All @@ -751,7 +751,7 @@ function append!(B::BitVector, items::BitVector)
k0 = length(Bc)
k1 = num_bit_chunks(n0 + n1)
if k1 > k0
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, k1 - k0)
_growend!(Bc, k1 - k0)
Bc[end] = UInt64(0)
end
B.len += n1
Expand All @@ -770,7 +770,7 @@ function prepend!(B::BitVector, items::BitVector)
k0 = length(Bc)
k1 = num_bit_chunks(n0 + n1)
if k1 > k0
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, k1 - k0)
_growend!(Bc, k1 - k0)
Bc[end] = UInt64(0)
end
B.len += n1
Expand Down Expand Up @@ -799,7 +799,7 @@ function resize!(B::BitVector, n::Integer)
k0 = length(Bc)
k1 = num_bit_chunks(Int(n))
if k1 > k0
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, k1 - k0)
_growend!(Bc, k1 - k0)
Bc[end] = UInt64(0)
end
B.len = n
Expand All @@ -812,7 +812,7 @@ function pop!(B::BitVector)
B[end] = false

l = _mod64(length(B))
l == 1 && ccall(:jl_array_del_end, Cvoid, (Any, UInt), B.chunks, 1)
l == 1 && _deleteend!(B.chunks, 1)
B.len -= 1

return item
Expand All @@ -825,7 +825,7 @@ function pushfirst!(B::BitVector, item)

l = _mod64(length(B))
if l == 0
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, 1)
_growend!(Bc, 1)
Bc[end] = UInt64(0)
end
B.len += 1
Expand Down Expand Up @@ -853,7 +853,7 @@ function popfirst!(B::BitVector)

l = _mod64(length(B))
if l == 1
ccall(:jl_array_del_end, Cvoid, (Any, UInt), Bc, 1)
_deleteend!(Bc, 1)
else
Bc[end] >>>= 1
end
Expand All @@ -874,7 +874,7 @@ function insert!(B::BitVector, i::Integer, item)

l = _mod64(length(B))
if l == 0
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, 1)
_growend!(Bc, 1)
Bc[end] = UInt64(0)
end
B.len += 1
Expand Down Expand Up @@ -912,7 +912,7 @@ function _deleteat!(B::BitVector, i::Integer)
l = _mod64(length(B))

if l == 1
ccall(:jl_array_del_end, Cvoid, (Any, UInt), Bc, 1)
_deleteend!(Bc, 1)
elseif length(Bc) > k
Bc[end] >>>= 1
end
Expand Down Expand Up @@ -943,7 +943,7 @@ function deleteat!(B::BitVector, r::UnitRange{Int})

copy_chunks!(Bc, i_f, Bc, i_l+1, n-i_l)

delta_k < 0 && ccall(:jl_array_del_end, Cvoid, (Any, UInt), Bc, -delta_k)
delta_k < 0 && _deleteend!(Bc, -delta_k)

B.len = new_l

Expand Down Expand Up @@ -981,7 +981,7 @@ function deleteat!(B::BitVector, inds)
q <= n && copy_chunks!(Bc, p, Bc, q, n-q+1)

delta_k = num_bit_chunks(new_l) - length(Bc)
delta_k < 0 && ccall(:jl_array_del_end, Cvoid, (Any, UInt), Bc, -delta_k)
delta_k < 0 && _deleteend!(Bc, -delta_k)

B.len = new_l

Expand Down Expand Up @@ -1028,12 +1028,12 @@ function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins::AbstractA
new_l = length(B) + lins - ldel
delta_k = num_bit_chunks(new_l) - length(Bc)

delta_k > 0 && ccall(:jl_array_grow_end, Cvoid, (Any, UInt), Bc, delta_k)
delta_k > 0 && _growend!(Bc, delta_k)

copy_chunks!(Bc, i_f+lins, Bc, i_l+1, n-i_l)
copy_chunks!(Bc, i_f, Bins.chunks, 1, lins)

delta_k < 0 && ccall(:jl_array_del_end, Cvoid, (Any, UInt), Bc, -delta_k)
delta_k < 0 && _deleteend!(Bc, -delta_k)

B.len = new_l

Expand All @@ -1056,7 +1056,7 @@ end


function empty!(B::BitVector)
ccall(:jl_array_del_end, Cvoid, (Any, UInt), B.chunks, length(B.chunks))
_deleteend!(B.chunks, length(B.chunks))
B.len = 0
return B
end
Expand Down
5 changes: 2 additions & 3 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ function append_any(xs...)
for x in xs
for y in x
if i > l
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), out, 16)
_growend!(out, 16)
l += 16
end
Core.arrayset(true, out, y, i)
i += 1
end
end
ccall(:jl_array_del_end, Cvoid, (Any, UInt), out, l-i+1)
_deleteend!(out, l-i+1)
out
end

Expand Down Expand Up @@ -764,4 +764,3 @@ ismissing(::Missing) = true

function popfirst! end
function peek end

0 comments on commit b302238

Please sign in to comment.