Skip to content
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

Merged
merged 1 commit into from
Feb 22, 2018

Conversation

masterleinad
Copy link
Member

@masterleinad masterleinad commented Feb 21, 2018

Working with @tjhei on doing CI with clang-tidy we found some more places to fix.

@@ -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);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@tjhei tjhei Feb 21, 2018

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.

Copy link
Member Author

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 😕

@masterleinad
Copy link
Member Author

Now, I just mark all the cases where we would create a reference to a local copy as NOLINT and clang-tidy ignores them.

@masterleinad
Copy link
Member Author

/run-tests

@tjhei
Copy link
Member

tjhei commented Feb 21, 2018

Does anybody want to hit "merge" here? I think this is good to go.

@drwells drwells merged commit 69bb195 into dealii:master Feb 22, 2018
@masterleinad masterleinad deleted the more_clang_tidy_performance branch March 21, 2018 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants