Skip to content

Commit d2262c8

Browse files
committed
use narrower type when possible as per rfourqet
1 parent 2fcc479 commit d2262c8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/Random/src/misc.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(
185185

186186
function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N}
187187
@inline let # `@inline` and `@inbounds` are here to help escape analysis
188-
clo = @inbounds let mem = Memory{UInt16}(undef, N) # use `UInt16` to save stack space/prevent heap allocation
188+
Ind = (N <= 0xff) ? UInt8 : UInt16 # use a narrow integer type to save stack space and prevent heap allocation
189+
clo = @inbounds let mem = Memory{Ind}(undef, N)
189190
randperm!(rng, mem)
190191
let mem = mem, tup = tup
191192
function closure(i::Int)

0 commit comments

Comments
 (0)