Skip to content

Commit

Permalink
Load some BitArray machinery sooner during bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Mar 10, 2015
1 parent 515ebed commit aecda29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
19 changes: 18 additions & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ bitpack{T,N}(A::AbstractArray{T,N}) = convert(BitArray{N}, A)
@inbounds r = (Bc[i1] & u) != 0
return r
end
@inline unsafe_getindex(v::BitArray, ind::Int) = Base.unsafe_bitgetindex(v.chunks, ind)

@inline function getindex(B::BitArray, i::Int)
1 <= i <= length(B) || throw(BoundsError(B, i))
Expand Down Expand Up @@ -414,6 +415,7 @@ end
end
end
end
@inline unsafe_setindex!(v::BitArray, x::Bool, ind::Int) = (Base.unsafe_bitsetindex!(v.chunks, x, ind); v)

setindex!(B::BitArray, x) = setindex!(B, convert(Bool,x), 1)

Expand All @@ -423,6 +425,21 @@ function setindex!(B::BitArray, x::Bool, i::Int)
return B
end

function unsafe_setindex!(B::BitArray, X::BitArray, I0::UnitRange{Int})
l0 = length(I0)
l0 == 0 && return B
f0 = first(I0)
copy_chunks!(B.chunks, f0, X.chunks, 1, l0)
return B
end

function unsafe_setindex!(B::BitArray, x::Bool, I0::UnitRange{Int})
l0 = length(I0)
l0 == 0 && return B
f0 = first(I0)
fill_chunks!(B.chunks, x, f0, l0)
return B
end
# logical indexing
# (when the indexing is provided as an Array{Bool} or a BitArray we can be
# sure about the behaviour and use unsafe_getindex; in the general case
Expand Down Expand Up @@ -803,7 +820,7 @@ function splice!(B::BitVector, r::Union(UnitRange{Int}, Integer), ins::AbstractA
i_f = first(r)
i_l = last(r)

1 <= i_f <= n+1 || throw(BoundsError(B, i_f))
1 <= i_f || throw(BoundsError(B, i_f))
i_l <= n || throw(BoundsError(B, n+1))

Bins = convert(BitArray, ins)
Expand Down
18 changes: 0 additions & 18 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ stagedfunction checksize(A::AbstractArray, I...)
end
end

@inline unsafe_getindex(v::BitArray, ind::Int) = Base.unsafe_bitgetindex(v.chunks, ind)

@inline unsafe_setindex!{T}(v::Array{T}, x::T, ind::Int) = (@inbounds v[ind] = x; v)
@inline unsafe_setindex!{T}(v::AbstractArray{T}, x::T, ind::Int) = (v[ind] = x; v)
@inline unsafe_setindex!(v::BitArray, x::Bool, ind::Int) = (Base.unsafe_bitsetindex!(v.chunks, x, ind); v)
@inline unsafe_setindex!{T}(v::AbstractArray{T}, x::T, ind::Real) = unsafe_setindex!(v, x, to_index(ind))

# Version that uses cartesian indexing for src
Expand Down Expand Up @@ -653,22 +651,6 @@ end
# contiguous multidimensional indexing: if the first dimension is a range,
# we can get some performance from using copy_chunks!

function unsafe_setindex!(B::BitArray, X::BitArray, I0::UnitRange{Int})
l0 = length(I0)
l0 == 0 && return B
f0 = first(I0)
copy_chunks!(B.chunks, f0, X.chunks, 1, l0)
return B
end

function unsafe_setindex!(B::BitArray, x::Bool, I0::UnitRange{Int})
l0 = length(I0)
l0 == 0 && return B
f0 = first(I0)
fill_chunks!(B.chunks, x, f0, l0)
return B
end

stagedfunction unsafe_setindex!(B::BitArray, X::BitArray, I0::UnitRange{Int}, I::Union(Int,UnitRange{Int})...)
N = length(I)
quote
Expand Down

0 comments on commit aecda29

Please sign in to comment.