Skip to content

Commit

Permalink
improve minor inferrabilities (#42141)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Sep 8, 2021
1 parent 3a4198e commit 9e99af6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
empty!(innerlist)
end

C = eltype(str)
P = Pair{Int,C}
for (j, c) in st
j, c = j::Int, c::eltype(str)
j, c = j::Int, c::C
if !in_single_quotes && !in_double_quotes && isspace(c)
i = consume_upto!(arg, s, i, j)
append_2to1!(args, arg)
while !isempty(st)
# We've made sure above that we don't end in whitespace,
# so updating `i` here is ok
(i, c) = peek(st)::Pair{Int,eltype(str)}
(i, c) = peek(st)::P
isspace(c) || break
popfirst!(st)
end
elseif interpolate && !in_single_quotes && c == '$'
i = consume_upto!(arg, s, i, j)
isempty(st) && error("\$ right before end of command")
stpos, c = popfirst!(st)::Pair{Int,eltype(str)}
stpos, c = popfirst!(st)::P
isspace(c) && error("space not allowed right after \$")
if startswith(SubString(s, stpos), "var\"")
# Disallow var"#" syntax in cmd interpolations.
Expand All @@ -88,19 +90,19 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
in_double_quotes = !in_double_quotes
i = consume_upto!(arg, s, i, j)
elseif !in_single_quotes && c == '\\'
if !isempty(st) && peek(st)[2] in ('\n', '\r')
if !isempty(st) && (peek(st)::P)[2] in ('\n', '\r')
i = consume_upto!(arg, s, i, j) + 1
if popfirst!(st)[2] == '\r' && peek(st)[2] == '\n'
if popfirst!(st)[2] == '\r' && (peek(st)::P)[2] == '\n'
i += 1
popfirst!(st)
end
while !isempty(st) && peek(st)[2] in (' ', '\t')
while !isempty(st) && (peek(st)::P)[2] in (' ', '\t')
i = nextind(str, i)
_ = popfirst!(st)
end
elseif in_double_quotes
isempty(st) && error("unterminated double quote")
k, c′ = peek(st)
k, c′ = peek(st)::P
if c′ == '"' || c′ == '$' || c′ == '\\'
i = consume_upto!(arg, s, i, j)
_ = popfirst!(st)
Expand Down
2 changes: 1 addition & 1 deletion base/strings/unicode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ function iterate(g::GraphemeIterator, i_=(Int32(0),firstindex(g.s)))
y === nothing && return nothing
c0, k = y
while k <= ncodeunits(s) # loop until next grapheme is s[i:j]
c, ℓ = iterate(s, k)
c, ℓ = iterate(s, k)::NTuple{2,Any}
isgraphemebreak!(state, c0, c) && break
j = k
k =
Expand Down

0 comments on commit 9e99af6

Please sign in to comment.