From 3a8da6a3f47ca98894fd8dd88379864c022aea03 Mon Sep 17 00:00:00 2001 From: Carlo Baldassi Date: Sun, 17 Aug 2014 04:06:40 +0200 Subject: [PATCH] Fix #8025 (findfirst(::Function,::BitArray)) --- base/bitarray.jl | 12 ++++++------ test/bitarray.jl | 29 ++++++++++++++--------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/base/bitarray.jl b/base/bitarray.jl index 7d65700b3f60c..0c5dfbf6e6198 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1280,20 +1280,20 @@ function findnextnot(B::BitArray, start::Integer) within_chunk_start = @_mod64(start-1) mask = ~(_msk64 << within_chunk_start) - @inbounds begin + @inbounds if chunk_start < l if Bc[chunk_start] | mask != _msk64 return (chunk_start-1) << 6 + trailing_ones(Bc[chunk_start] | mask) + 1 end - for i = chunk_start+1:l-1 if Bc[i] != _msk64 return (i-1) << 6 + trailing_ones(Bc[i]) + 1 end end - ce = Bc[end] - end - if ce != @_msk_end length(B) - return (l-1) << 6 + trailing_ones(ce) + 1 + if Bc[l] != @_msk_end length(B) + return (l-1) << 6 + trailing_ones(Bc[l]) + 1 + end + elseif Bc[l] | mask != @_msk_end length(B) + return (l-1) << 6 + trailing_ones(Bc[l] | mask) + 1 end return 0 end diff --git a/test/bitarray.jl b/test/bitarray.jl index 073c8974e4630..c7dd7125474c0 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -809,23 +809,22 @@ timesofar("datamove") ## countnz & find ## -b1 = randbool(v1) -@check_bit_operation countnz(b1) Int +for m = 0:v1, b1 in {randbool(m), trues(m), falses(m)} + @check_bit_operation countnz(b1) Int -@check_bit_operation findfirst(b1) Int -@check_bit_operation findfirst(trues(v1)) Int -@check_bit_operation findfirst(falses(v1)) Int + @check_bit_operation findfirst(b1) Int -@check_bit_operation findfirst(b1, true) Int -@check_bit_operation findfirst(b1, false) Int -@check_bit_operation findfirst(b1, 3) Int + @check_bit_operation findfirst(b1, true) Int + @check_bit_operation findfirst(b1, false) Int + @check_bit_operation findfirst(b1, 3) Int -@check_bit_operation findfirst(x->x, b1) Int -@check_bit_operation findfirst(x->!x, b1) Int -@check_bit_operation findfirst(x->true, b1) Int -@check_bit_operation findfirst(x->false, b1) Int + @check_bit_operation findfirst(x->x, b1) Int + @check_bit_operation findfirst(x->!x, b1) Int + @check_bit_operation findfirst(x->true, b1) Int + @check_bit_operation findfirst(x->false, b1) Int -@check_bit_operation find(b1) Vector{Int} + @check_bit_operation find(b1) Vector{Int} +end b1 = trues(v1) for i = 0:v1-1 @@ -836,8 +835,8 @@ end for i = 3:v1-1 for j = 2:i submask = b1 << (v1-j+1) - @test findnext((b1 >> i) | submask,j) == i+1 - @test Base.findnextnot((~(b1 >> i)) $ submask,j) == i+1 + @test findnext((b1 >> i) | submask, j) == i+1 + @test Base.findnextnot((~(b1 >> i)) $ submask, j) == i+1 end end