Skip to content

Commit b8e36e7

Browse files
committed
Fix allocations
1 parent 63ad8a2 commit b8e36e7

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/solve.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function DiffEqBase.init(prob::NonlinearProblem{uType, iip}, alg::AbstractNewton
6060
fu = f(u, p)
6161
end
6262

63-
63+
6464
sol = build_newton_solution(u, Val(iip))
6565
if immutable
6666
return NewtonImmutableSolver(1, f, alg, u, fu, p, nothing, false, maxiters, internalnorm, :Default, tol, sol)
@@ -81,7 +81,7 @@ function DiffEqBase.solve!(solver::AbstractNonlinearSolver)
8181
if solver.iter == solver.maxiters
8282
solver.retcode = :MaxitersExceeded
8383
end
84-
set_solution!(solver)
84+
solver = set_solution(solver)
8585
return solver.sol
8686
end
8787

@@ -151,19 +151,25 @@ function check_for_exact_solution!(solver::BracketingSolver)
151151
return false
152152
end
153153

154-
function set_solution!(solver::BracketingSolver)
155-
solver.sol.left = solver.left
156-
solver.sol.right = solver.right
157-
solver.sol.retcode = solver.retcode
154+
function set_solution(solver::BracketingSolver)
155+
sol = solver.sol
156+
@set! sol.left = solver.left
157+
@set! sol.right = solver.right
158+
@set! sol.retcode = solver.retcode
159+
@set! solver.sol = sol
160+
return solver
158161
end
159162

160163
function get_solution(solver::BracketingImmutableSolver)
161164
return (left = solver.left, right = solver.right, retcode = solver.retcode)
162165
end
163166

164-
function set_solution!(solver::NewtonSolver)
165-
solver.sol.u = solver.u
166-
solver.sol.retcode = solver.retcode
167+
function set_solution(solver::NewtonSolver)
168+
sol = solver.sol
169+
@set! sol.u = solver.u
170+
@set! sol.retcode = solver.retcode
171+
@set! solver.sol = sol
172+
return solver
167173
end
168174

169175
function get_solution(solver::NewtonImmutableSolver)

src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function build_solution(u_prototype, ::Val{false})
8383
return BracketingSolution(zero(u_prototype), zero(u_prototype), :Default)
8484
end
8585

86-
mutable struct NewtonSolution{uType}
86+
struct NewtonSolution{uType}
8787
u::uType
8888
retcode::Symbol
8989
end

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ sol = benchmark_mutable(f, u0)
2929
sol = benchmark_scalar(sf, su0)
3030
@test sol * sol - 2 < 1e-9
3131

32-
@test_broken (@ballocated benchmark_immutable($f, $u0)) == 0
33-
@test_broken (@ballocated benchmark_mutable($f, $u0)) == 0
32+
@test (@ballocated benchmark_immutable($f, $u0)) == 0
33+
@test (@ballocated benchmark_mutable($f, $u0)) < 200
3434
@test (@ballocated benchmark_scalar($sf, $su0)) == 0

0 commit comments

Comments
 (0)