From 9e99af6802edb56c2d812aaea2bc76333a0ed803 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Wed, 8 Sep 2021 17:30:22 +0900 Subject: [PATCH] improve minor inferrabilities (#42141) --- base/shell.jl | 16 +++++++++------- base/strings/unicode.jl | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/base/shell.jl b/base/shell.jl index bcece48681e5c..c0537821638f3 100644 --- a/base/shell.jl +++ b/base/shell.jl @@ -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. @@ -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) diff --git a/base/strings/unicode.jl b/base/strings/unicode.jl index cf215849ab08c..6e147194c5910 100644 --- a/base/strings/unicode.jl +++ b/base/strings/unicode.jl @@ -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 = ℓ