Skip to content

Commit 226892e

Browse files
committed
Make lower_index nicer
1 parent 782a965 commit 226892e

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/sugar.jl

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,13 @@ need_dynamic_optic(ex) =
147147
replace_underscore(ex, to) = postwalk(x -> x === :_ ? to : x, ex)
148148

149149
function lower_index(collection::Symbol, index, dim)
150-
index = MacroTools.replace(
151-
index, :end,
152-
dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
153-
)
154-
index = MacroTools.replace(
155-
index, :begin,
156-
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
157-
)
150+
lasti = dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
151+
firsti = dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
152+
index = MacroTools.replace(index, :end, lasti)
153+
index = MacroTools.replace(index, :begin, firsti)
158154
# New syntax for begin/end in indexing expression, see https://github.com/JuliaLang/julia/pull/57368
159-
index = MacroTools.replace(
160-
index, Expr(:end),
161-
dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
162-
)
163-
index = MacroTools.replace(
164-
index, Expr(:begin),
165-
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
166-
)
155+
index = MacroTools.replace(index, Expr(:end), lasti)
156+
index = MacroTools.replace(index, Expr(:begin), firsti)
167157
end
168158

169159
_secondarg(_, x) = x

0 commit comments

Comments
 (0)