@@ -133,10 +133,11 @@ function mul!(
133133 increase_nprod! (p)
134134 end
135135 conj! (res)
136+ vc = eltype (v) <: Real ? v : conj .(v) # avoid unnecessary allocations if v has real elements
136137 if use_p5!
137- tprod! (res, conj .(v) , conj (α), conj (β))
138+ tprod! (res, vc , conj (α), conj (β))
138139 else
139- prod3! (res, tprod!, conj .(v) , conj (α), conj (β), p. Mtu5)
140+ prod3! (res, tprod!, vc , conj (α), conj (β), p. Mtu5)
140141 end
141142 conj! (res)
142143end
@@ -199,10 +200,11 @@ function mul!(
199200 increase_nprod! (p)
200201 end
201202 conj! (res)
203+ vc = eltype (v) <: Real ? v : conj .(v) # avoid unnecessary allocations when v has real elements
202204 if use_p5!
203- ctprod! (res, conj .(v) , conj (α), conj (β))
205+ ctprod! (res, vc , conj (α), conj (β))
204206 else
205- prod3! (res, ctprod!, conj .(v) , conj (α), conj (β), p. Mtu5)
207+ prod3! (res, ctprod!, vc , conj (α), conj (β), p. Mtu5)
206208 end
207209 conj! (res)
208210end
@@ -234,7 +236,8 @@ function mul!(
234236 β,
235237) where {T, S}
236238 p = op. parent
237- mul! (res, p, conj .(v), α, β)
239+ vc = eltype (v) <: Real ? v : conj .(v) # avoid unnecessary allocations if v has real elements
240+ mul! (res, p, vc, α, β)
238241 conj! (res)
239242end
240243
@@ -246,7 +249,7 @@ function mul!(
246249 β,
247250) where {T, S}
248251 p = op. parent
249- mul! (res, p, v, α, β) # this gets called for A'*v when v is real, so we can skip the conjugation
252+ mul! (res, p, v, α, β) # we can skip `conj.(v)` since it has real elements (this avoids unnecessary allocations)
250253 conj! (res)
251254end
252255
0 commit comments