Skip to content

Commit 5b34204

Browse files
refactor: minor type-stability improvements
1 parent f039e65 commit 5b34204

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

lib/ModelingToolkitBase/src/systems/index_cache.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,20 @@ function reorder_parameters(ic::IndexCache, ps::Vector{SymbolicT}; drop_missing
644644
if i isa Int
645645
param_buf[i] = p
646646
else
647-
param_buf[i] = collect(p)
647+
i = (first(i)::Int):(last(i)::Int)
648+
for (buf_i, p_i) in zip(i, SU.stable_eachindex(p))
649+
param_buf[buf_i] = p[p_i]
650+
end
648651
end
649652
elseif haskey(ic.initials_idx, p)
650653
i = ic.initials_idx[p]
651654
if i isa Int
652655
initials_buf[i] = p
653656
else
654-
initials_buf[i] = collect(p)
657+
i = (first(i)::Int):(last(i)::Int)
658+
for (buf_i, p_i) in zip(i, SU.stable_eachindex(p))
659+
initials_buf[buf_i] = p[p_i]
660+
end
655661
end
656662
elseif haskey(ic.constant_idx, p)
657663
i, j = ic.constant_idx[p]

lib/ModelingToolkitBase/src/systems/system.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ end
11761176
11771177
Get the metadata associated with key `k` in system `sys` or `default` if it does not exist.
11781178
"""
1179-
function SymbolicUtils.getmetadata(sys::AbstractSystem, k::DataType, default)
1179+
function SymbolicUtils.getmetadata(sys::AbstractSystem, @nospecialize(k::DataType), default)
11801180
meta = get_metadata(sys)
11811181
return get(meta, k, default)
11821182
end
@@ -1188,7 +1188,7 @@ Set the metadata associated with key `k` in system `sys` to value `v`. This is a
11881188
out-of-place operation, and will return a shallow copy of `sys` with the appropriate
11891189
metadata values.
11901190
"""
1191-
function SymbolicUtils.setmetadata(sys::AbstractSystem, k::DataType, v)
1191+
function SymbolicUtils.setmetadata(sys::AbstractSystem, @nospecialize(k::DataType), @nospecialize(v))
11921192
meta = get_metadata(sys)
11931193
meta = Base.ImmutableDict(meta, k => v)::MetadataT
11941194
return @set sys.metadata = meta

0 commit comments

Comments
 (0)