Skip to content

Commit 358337b

Browse files
nsajkoKristofferC
authored andcommitted
Base: append!, resize!: convert length to Int before passing it on (#57585)
Reduces the number of invalidations from 512 to 505 on running this code: ```julia struct I <: Integer end Base.Int(::I) = 7 ``` (cherry picked from commit a97137e)
1 parent dec7072 commit 358337b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

base/array.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ function append! end
13201320

13211321
function append!(a::Vector{T}, items::Union{AbstractVector{<:T},Tuple}) where T
13221322
items isa Tuple && (items = map(x -> convert(T, x), items))
1323-
n = length(items)
1323+
n = Int(length(items))::Int
13241324
_growend!(a, n)
13251325
copyto!(a, length(a)-n+1, items, firstindex(items), n)
13261326
return a
@@ -1444,7 +1444,8 @@ julia> a[1:6]
14441444
1
14451445
```
14461446
"""
1447-
function resize!(a::Vector, nl::Integer)
1447+
function resize!(a::Vector, nl_::Integer)
1448+
nl = Int(nl_)::Int
14481449
l = length(a)
14491450
if nl > l
14501451
_growend!(a, nl-l)

0 commit comments

Comments
 (0)