Skip to content

Commit 295b503

Browse files
jakobnissenKristofferC
authored andcommitted
Improve type stability of array_subpadding slightly (#48136)
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.
1 parent 4a46ccb commit 295b503

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

base/reinterpretarray.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,18 @@ end
725725
@assume_effects :total function array_subpadding(S, T)
726726
lcm_size = lcm(sizeof(S), sizeof(T))
727727
s, t = CyclePadding(S), CyclePadding(T)
728-
isempty(t) && return true
729-
isempty(s) && return false
730728
checked_size = 0
731-
ps, sstate = iterate(s) # use of Stateful harms inference and makes this vulnerable to invalidation
732-
pad, tstate = iterate(t)
729+
# use of Stateful harms inference and makes this vulnerable to invalidation
730+
(pad, tstate) = let
731+
it = iterate(t)
732+
it === nothing && return true
733+
it
734+
end
735+
(ps, sstate) = let
736+
it = iterate(s)
737+
it === nothing && return false
738+
it
739+
end
733740
while checked_size < lcm_size
734741
while true
735742
# See if there's corresponding padding in S

0 commit comments

Comments
 (0)