From 5baa1a012ee7aa8c54c19fd3444813e447b7d96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 21 May 2024 10:29:49 +0200 Subject: [PATCH] Fix allocation test --- src/sparse_coeffs.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sparse_coeffs.jl b/src/sparse_coeffs.jl index 4d8e031..95676a1 100644 --- a/src/sparse_coeffs.jl +++ b/src/sparse_coeffs.jl @@ -68,7 +68,10 @@ function MA.operate!(::typeof(canonical), res::SparseCoefficients) return MA.operate!(canonical, res, comparable(key_type(res))) end -function MA.operate!(::typeof(canonical), res::SparseCoefficients, cmp) +# `::C` is needed to force Julia specialize on the function type +# Otherwise, we get one allocation when we call `issorted` +# See https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing +function MA.operate!(::typeof(canonical), res::SparseCoefficients, cmp::C) where {C} sorted = issorted(res.basis_elements; lt = cmp) distinct = allunique(res.basis_elements) if sorted && distinct && !any(iszero, res.values)