Skip to content

Commit

Permalink
replace length(x) == 0 with isempty(x), similarly for !isempty
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Oct 29, 2015
1 parent f8a4340 commit a0ef8ca
Show file tree
Hide file tree
Showing 33 changed files with 77 additions and 73 deletions.
6 changes: 3 additions & 3 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ input_string(s::PromptState) = bytestring(s.input_buffer)
input_string_newlines(s::PromptState) = count(c->(c == '\n'), input_string(s))
function input_string_newlines_aftercursor(s::PromptState)
str = input_string(s)
length(str) == 0 && return 0
isempty(str) && return 0
rest = str[nextind(str, position(s.input_buffer)):end]
return count(c->(c == '\n'), rest)
end
Expand Down Expand Up @@ -143,7 +143,7 @@ end
complete_line(s::MIState) = complete_line(s.mode_state[s.current_mode], s.key_repeats)
function complete_line(s::PromptState, repeats)
completions, partial, should_complete = complete_line(s.p.complete, s)
if length(completions) == 0
if isempty(completions)
beep(terminal(s))
elseif !should_complete
# should_complete is false for cases where we only want to show
Expand All @@ -156,7 +156,7 @@ function complete_line(s::PromptState, repeats)
edit_replace(s, position(s.input_buffer), prev_pos, completions[1])
else
p = common_prefix(completions)
if length(p) > 0 && p != partial
if !isempty(p) && p != partial
# All possible completions share the same prefix, so we might as
# well complete that
prev_pos = position(s.input_buffer)
Expand Down
4 changes: 2 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function add_history(hist::REPLHistoryProvider, s)
str = rstrip(bytestring(s.input_buffer))
isempty(strip(str)) && return
mode = mode_idx(hist, LineEdit.mode(s))
length(hist.history) > 0 &&
!isempty(hist.history) &&
mode == hist.modes[end] && str == hist.history[end] && return
push!(hist.modes, mode)
push!(hist.history, str)
Expand Down Expand Up @@ -507,7 +507,7 @@ function history_move_prefix(s::LineEdit.PrefixSearchState,
if (idx == max_idx) || (startswith(hist.history[idx], prefix) && (hist.history[idx] != cur_response || hist.modes[idx] != LineEdit.mode(s)))
m = history_move(s, hist, idx)
if m == :ok
if length(prefix) == 0
if isempty(prefix)
# on empty prefix search, move cursor to the end
LineEdit.move_input_end(s)
else
Expand Down
4 changes: 2 additions & 2 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function complete_path(path::AbstractString, pos)
end
local files
try
if length(dir) == 0
if isempty(dir)
files = readdir()
elseif isdir(dir)
files = readdir(dir)
Expand All @@ -146,7 +146,7 @@ function complete_path(path::AbstractString, pos)
# The pos - endof(prefix) + 1 is correct due to `endof(prefix)-endof(prefix)==0`,
# hence we need to add one to get the first index. This is also correct when considering
# pos, because pos is the `endof` a larger string which `endswith(path)==true`.
return matches, startpos:pos, length(matches) > 0
return matches, startpos:pos, !isempty(matches)
end

# Determines whether method_complete should be tried. It should only be done if
Expand Down
4 changes: 2 additions & 2 deletions base/ascii.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ function string(c::ASCIIString...)
end

function ucfirst(s::ASCIIString)
if length(s) > 0 && 'a' <= s[1] <= 'z'
if !isempty(s) && 'a' <= s[1] <= 'z'
t = ASCIIString(copy(s.data))
t.data[1] -= 32
return t
end
return s
end
function lcfirst(s::ASCIIString)
if length(s) > 0 && 'A' <= s[1] <= 'Z'
if !isempty(s) && 'A' <= s[1] <= 'Z'
t = ASCIIString(copy(s.data))
t.data[1] += 32
return t
Expand Down
4 changes: 2 additions & 2 deletions base/base64.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type Base64DecodePipe <: IO
end

function read(b::Base64DecodePipe, t::Type{UInt8})
if length(b.cache) > 0
if !isempty(b.cache)
return shift!(b.cache)
else
empty!(b.encvec)
Expand All @@ -193,7 +193,7 @@ function read(b::Base64DecodePipe, t::Type{UInt8})
end
end

eof(b::Base64DecodePipe) = length(b.cache) == 0 && eof(b.io)
eof(b::Base64DecodePipe) = isempty(b.cache) && eof(b.io)
close(b::Base64DecodePipe) = nothing

# Decodes a base64-encoded string
Expand Down
10 changes: 5 additions & 5 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ similar(B::BitArray, T::Type, dims::Dims) = Array(T, dims)

function fill!(B::BitArray, x)
y = convert(Bool, x)
length(B) == 0 && return B
isempty(B) && return B
Bc = B.chunks
if !y
fill!(Bc, 0)
Expand Down Expand Up @@ -1488,7 +1488,7 @@ sum(A::BitArray, region) = reducedim(AddFun(), A, region)
sum(B::BitArray) = countnz(B)

function all(B::BitArray)
length(B) == 0 && return true
isempty(B) && return true
Bc = B.chunks
@inbounds begin
for i = 1:length(Bc)-1
Expand All @@ -1500,7 +1500,7 @@ function all(B::BitArray)
end

function any(B::BitArray)
length(B) == 0 && return false
isempty(B) && return false
Bc = B.chunks
@inbounds begin
for i = 1:length(Bc)
Expand Down Expand Up @@ -1533,7 +1533,7 @@ map!(f::Function, dest::BitArray, A::BitArray, B::BitArray) = map!(specialized_b
# iterates bit-by-bit.
function map!(f::BitFunctorUnary, dest::BitArray, A::BitArray)
size(A) == size(dest) || throw(DimensionMismatch("sizes of dest and A must match"))
length(A) == 0 && return dest
isempty(A) && return dest
for i=1:length(A.chunks)-1
dest.chunks[i] = f(A.chunks[i])
end
Expand All @@ -1542,7 +1542,7 @@ function map!(f::BitFunctorUnary, dest::BitArray, A::BitArray)
end
function map!(f::BitFunctorBinary, dest::BitArray, A::BitArray, B::BitArray)
size(A) == size(B) == size(dest) || throw(DimensionMismatch("sizes of dest, A, and B must all match"))
length(A) == 0 && return dest
isempty(A) && return dest
for i=1:length(A.chunks)-1
dest.chunks[i] = f(A.chunks[i], B.chunks[i])
end
Expand Down
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function init_parallel()
global PGRP
global LPROC
LPROC.id = 1
assert(length(PGRP.workers) == 0)
assert(isempty(PGRP.workers))
register_worker(LPROC)
end

Expand Down
4 changes: 2 additions & 2 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ permutations(a) = Permutations(a)
start(p::Permutations) = [1:length(p.a);]
function next(p::Permutations, s)
perm = [p.a[si] for si in s]
if length(p.a) == 0
if isempty(p.a)
# special case to generate 1 result for len==0
return (perm,[1])
end
Expand Down Expand Up @@ -456,7 +456,7 @@ end
# vector b of length n describing the first index b[i] that belongs to partition i
# integer n

done(p::FixedSetPartitions, s) = length(s[1]) == 0 || s[1][1] > 1
done(p::FixedSetPartitions, s) = isempty(s[1]) || s[1][1] > 1
next(p::FixedSetPartitions, s) = nextfixedsetpartition(p.s,p.m, s...)

function nextfixedsetpartition(s::AbstractVector, m, a, b, n)
Expand Down
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function localize_vars(expr, esca)
end

function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
if length(args) == 0
if isempty(args)
tag = sym
else
tag = Expr(sym, args...)
Expand Down
2 changes: 1 addition & 1 deletion base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function fix_kinds(region, kinds)
if length(kinds) > length(region)
throw(ArgumentError("too many transform kinds"))
else
if length(kinds) == 0
if isempty(kinds)
throw(ArgumentError("must supply a transform kind"))
end
k = Array(Int32, length(region))
Expand Down
8 changes: 4 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool, vars)
end
elseif isa(t,DataType)
P = t.parameters
length(P) == 0 && return t
isempty(P) && return t
if d > MAX_TYPE_DEPTH
R = t.name.primary
else
Expand Down Expand Up @@ -297,7 +297,7 @@ const getfield_tfunc = function (A, s0, name)
for i=1:length(snames)
if is(snames[i],fld)
R = s.types[i]
if length(s.parameters) == 0
if isempty(s.parameters)
return R, true
else
typ = limit_type_depth(R, 0, true,
Expand Down Expand Up @@ -2328,7 +2328,7 @@ function inlineable(f::ANY, e::Expr, atype::ANY, sv::StaticVarInfo, enclosing_as
methfunc = f
end

if length(methfunc.env) > 0
if !isempty(methfunc.env)
# can't inline something with an env
return NF
end
Expand Down Expand Up @@ -2866,7 +2866,7 @@ function inlining_pass(e::Expr, sv, ast)
end
if isa(res[2],Array)
res2 = res[2]::Array{Any,1}
if length(res2) > 0
if !isempty(res2)
prepend!(stmts,res2)
if !has_stmts
for stmt in res2
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function merge!(repo::GitRepo;
if committish == Consts.FETCH_HEAD # merge FETCH_HEAD
fheads = fetchheads(repo)
filter!(fh->fh.ismerge, fheads)
if length(fheads) == 0
if isempty(fheads)
throw(Error.GitError(Error.Merge,Error.ERROR,
"There is no fetch reference for this branch."))
end
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function credentials_callback(cred::Ptr{Ptr{Void}}, url_ptr::Cstring,
userpass = prompt("Password for '$username@$url'", password=true)
end

length(username) == 0 && length(userpass) == 0 && return Cint(-1)
isempty(username) && isempty(userpass) && return Cint(-1)

err = ccall((:git_cred_userpass_plaintext_new, :libgit2), Cint,
(Ptr{Ptr{Void}}, Cstring, Cstring),
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/commit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function commit(repo::GitRepo, msg::AbstractString;
end

# Retrieve parents from HEAD
if length(parent_ids) == 0
if isempty(parent_ids)
try # if throws then HEAD not found -> empty repo
push!(parent_ids, Oid(repo, refname))
end
Expand Down
4 changes: 2 additions & 2 deletions base/libgit2/remote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function fetch{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T};
options::FetchOptions = FetchOptions(),
msg::AbstractString="")
msg = "libgit2.fetch: $msg"
no_refs = (length(refspecs) == 0)
no_refs = isempty(refspecs)
!no_refs && (sa = StrArrayStruct(refspecs...))
try
@check ccall((:git_remote_fetch, :libgit2), Cint,
Expand All @@ -78,7 +78,7 @@ end
function push{T<:AbstractString}(rmt::GitRemote, refspecs::Vector{T};
force::Bool = false,
options::PushOptions = PushOptions())
no_refs = (length(refspecs) == 0)
no_refs = (isempty(refspecs))
!no_refs && (sa = StrArrayStruct(refspecs...))
try
@check ccall((:git_remote_push, :libgit2), Cint,
Expand Down
4 changes: 2 additions & 2 deletions base/libgit2/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ end
isset(val::Integer, flag::Integer) = (val & flag == flag)

function prompt(msg::AbstractString; default::AbstractString="", password::Bool=false)
msg = length(default) > 0 ? msg*" [$default]:" : msg*":"
msg = !isempty(default) ? msg*" [$default]:" : msg*":"
uinput = if password
bytestring(ccall(:getpass, Cstring, (Cstring,), msg))
else
print(msg)
chomp(readline(STDIN))
end
length(uinput) == 0 ? default : uinput
isempty(uinput) ? default : uinput
end
2 changes: 1 addition & 1 deletion base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function pinv{T}(D::Diagonal{T})
end
function pinv{T}(D::Diagonal{T}, tol::Real)
Di = similar(D.diag)
if( length(D.diag) != 0 ) maxabsD = maximum(abs(D.diag)) end
if( !isempty(D.diag) ) maxabsD = maximum(abs(D.diag)) end
for i = 1:length(D.diag)
if( abs(D.diag[i]) > tol*maxabsD && isfinite(inv(D.diag[i])) )
Di[i]=inv(D.diag[i])
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ Normalize the vector `v` with respect to the `p`-norm.
"""
function normalize(v::AbstractVector, p::Real = 2)
nrm = norm(v, p)
if length(v) > 0
if !isempty(v)
vv = copy_oftype(v, typeof(v[1]/nrm))
return __normalize!(vv, nrm)
else
Expand Down
18 changes: 9 additions & 9 deletions base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
if tA == 'N'
if tB == 'N'
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[i, 1]*B[1, j] + A[i, 1]*B[1, j])
Expand All @@ -522,7 +522,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
end
elseif tB == 'T'
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[i, 1]*B[j, 1] + A[i, 1]*B[j, 1])
Expand All @@ -534,7 +534,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
end
else
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[i, 1]*B[j, 1] + A[i, 1]*B[j, 1])
Expand All @@ -548,7 +548,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
elseif tA == 'T'
if tB == 'N'
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[1, i]*B[1, j] + A[1, i]*B[1, j])
Expand All @@ -560,7 +560,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
end
elseif tB == 'T'
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[1, i]*B[j, 1] + A[1, i]*B[j, 1])
Expand All @@ -572,7 +572,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
end
else
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[1, i]*B[j, 1] + A[1, i]*B[j, 1])
Expand All @@ -586,7 +586,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
else
if tB == 'N'
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[1, i]*B[1, j] + A[1, i]*B[1, j])
Expand All @@ -598,7 +598,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
end
elseif tB == 'T'
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[1, i]*B[j, 1] + A[1, i]*B[j, 1])
Expand All @@ -610,7 +610,7 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
end
else
for i = 1:mA, j = 1:nB
if length(A) == 0 || length(B) == 0
if isempty(A) || isempty(B)
Ctmp = zero(R)
else
Ctmp = zero(A[1, i]*B[j, 1] + A[1, i]*B[j, 1])
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Computes the polar decomposition of a vector.
"""
function qr(v::AbstractVector)
nrm = norm(v)
if length(v) > 0
if !isempty(v)
vv = copy_oftype(v, typeof(v[1]/nrm))
return __normalize!(vv, nrm), nrm
else
Expand Down
Loading

0 comments on commit a0ef8ca

Please sign in to comment.