Skip to content

Commit

Permalink
Base: append!, resize!: convert length to Int before passing …
Browse files Browse the repository at this point in the history
…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
```
  • Loading branch information
nsajko authored Mar 11, 2025
1 parent d369c10 commit a97137e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ function append! end

function append!(a::Vector{T}, items::Union{AbstractVector{<:T},Tuple}) where T
items isa Tuple && (items = map(x -> convert(T, x), items))
n = length(items)
n = Int(length(items))::Int
_growend!(a, n)
copyto!(a, length(a)-n+1, items, firstindex(items), n)
return a
Expand Down Expand Up @@ -1472,7 +1472,8 @@ julia> a[1:6]
1
```
"""
function resize!(a::Vector, nl::Integer)
function resize!(a::Vector, nl_::Integer)
nl = Int(nl_)::Int
l = length(a)
if nl > l
_growend!(a, nl-l)
Expand Down

0 comments on commit a97137e

Please sign in to comment.