-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang-tidy performance findings #5936
clang-tidy performance findings #5936
Conversation
source/fe/fe_dgq.cc
Outdated
@@ -698,7 +698,7 @@ FE_DGQArbitraryNodes<dim,spacedim>::FE_DGQArbitraryNodes (const Quadrature<1> &p | |||
{ | |||
Assert (points.size() > 0, | |||
(typename FiniteElement<dim, spacedim>::ExcFEHasNoSupportPoints ())); | |||
const Quadrature<dim> support_quadrature(points); | |||
const Quadrature<dim> &support_quadrature(points); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this and all of the other places you modify in a similar way make use of the fact that the initializer of the reference is a temporary whose lifetime is extended to the one of the reference (if dim>1) or it's an object of the same time (if dim==1). (In the mapping case above, it's either a copy of a MappingCollection, or a MappingCollection temp object created from a mapping.)
I find it unappealing to have these references because the semantics of initialization of a reference to a temporary are so difficult to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about we replace the code with:
if (dim==1)
this->unit_support_points = points.get_points();
else
this->unit_support_points = Quadrature<dim>(points).get_points();
This makes it more clear what is happening and should avoid the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that just works around the warning, doesn't it? I mean, clang presumably only complains in the 1d case because it says that there is no need to actually copy the quadrature formula, it's enough to take a reference. And in 2d/3d, putting a reference to the variable just happens to work. (Well, it's not coincidence, of course.) But in your replacement code, you still copy the argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in your replacement code, you still copy the argument.
I don't understand. I am not making a copy, the last line constructs a dim-dimensional quadrature from a 1 dimensional one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, that doesn't compile without using if constexpr
😕
8532633
to
e4d198c
Compare
Now, I just mark all the cases where we would create a reference to a local copy as |
e4d198c
to
284c85c
Compare
/run-tests |
Does anybody want to hit "merge" here? I think this is good to go. |
Working with @tjhei on doing CI with
clang-tidy
we found some more places to fix.