Skip to content

Commit

Permalink
Speedup transform(::Grid) by using inplace map!. (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnutAM authored Apr 11, 2023
1 parent 247d7c3 commit aa26130
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Grid/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,9 @@ end
Transform all nodes of the `grid` based on some transformation function `f`.
"""
function transform!(g::AbstractGrid, f::Function)
c = similar(g.nodes)
for i in 1:length(c)
c[i] = Node(f(g.nodes[i].x))
end
copyto!(g.nodes, c)
g
function transform!(g::Grid, f::Function)
map!(n -> Node(f(getcoordinates(n))), g.nodes, g.nodes)
return g
end

# Sets
Expand Down

0 comments on commit aa26130

Please sign in to comment.