Skip to content

Commit

Permalink
Improve type stability of array_subpadding slightly (#48136)
Browse files Browse the repository at this point in the history
This should be slightly more efficient as the compiler now only tries to call
`iterate` on `t` and `s` once, and will not try to destructure the result if
the `iterate` call returns `nothing`.
This change reduce spurious JET warnings.
  • Loading branch information
jakobnissen authored and kpamnany committed Jun 21, 2023
1 parent e9c9fd2 commit 5bc5100
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,18 @@ end
@assume_effects :total function array_subpadding(S, T)
lcm_size = lcm(sizeof(S), sizeof(T))
s, t = CyclePadding(S), CyclePadding(T)
isempty(t) && return true
isempty(s) && return false
checked_size = 0
ps, sstate = iterate(s) # use of Stateful harms inference and makes this vulnerable to invalidation
pad, tstate = iterate(t)
# use of Stateful harms inference and makes this vulnerable to invalidation
(pad, tstate) = let
it = iterate(t)
it === nothing && return true
it
end
(ps, sstate) = let
it = iterate(s)
it === nothing && return false
it
end
while checked_size < lcm_size
while true
# See if there's corresponding padding in S
Expand Down

0 comments on commit 5bc5100

Please sign in to comment.