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

STYLE: Add in-class {} initializers to classes with virtual functions #3913

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Feb 6, 2023

Added in-class {} default member initializers to data members of classes that have one or more virtual member functions.

For an object that has one or more virtual member functions, the performance cost of adding a {} default member initializer to each of its non-static data members should be acceptable, relative to cost of the initialization of its virtual table.

Follow-up to pull request #3851 commit 5e2c49f "STYLE: Add in-class {} member initializers to objects created by New()"

@github-actions github-actions bot added area:Bridge Issues affecting the Bridge module area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module type:Style Style changes: no logic impact (indentation, comments, naming) area:Numerics Issues affecting the Numerics module labels Feb 6, 2023
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you find all these classes?

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Feb 6, 2023

How did you find all these classes?

My script (in C++): https://gist.github.com/N-Dekker/738d28b8d7528a32c12e7a129160b00f

It looks for a line of code that start with virtual. If such a line is found, from there, it adds {} initializers to data members it encounters, until it encounters a line that starts with }; (Because }; means the end of class!)

@dzenanz
Copy link
Member

dzenanz commented Feb 6, 2023

Should this script be added to the repository?

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Feb 6, 2023

Should this script be added to the repository?

Maybe, but I don't want to maintain the script forever. Should the script itself then need to conform to the ITK coding guidelines?

@dzenanz
Copy link
Member

dzenanz commented Feb 6, 2023

I don't think so. It is a repository of scripts which were used once upon a time, and are therefore good starting points if you need the same thing again. You should add a short usage in the comments at the top of the script, so a future you/me/somebody else can make sense of what the script is for and how to invoke it.

@N-Dekker N-Dekker marked this pull request as ready for review February 6, 2023 20:43
Added in-class `{}` default member initializers to data members of classes
that have one or more virtual member functions.

For an object that has one or more virtual member functions, the performance
cost of adding a `{}` default member initializer to each of its non-static data
members should be acceptable, relative to cost of the initialization of its
virtual table.

Follow-up to pull request InsightSoftwareConsortium#3851
commit 5e2c49f
"STYLE: Add in-class `{}` member initializers to objects created by New()"
(which only looked at classes that have a `itkNewMacro`).
@N-Dekker N-Dekker force-pushed the in-class-initializers-for-classes-with-virtual-functions branch from 29374db to 6ba4e1d Compare February 8, 2023 11:17
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Feb 8, 2023

FYI, The force-push that I just did has included classes that have an override keyword.

@dzenanz
Copy link
Member

dzenanz commented Feb 8, 2023

Label PRs action build failure is unrelated to this PR.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Feb 8, 2023

Thanks for your approval, @dzenanz

One of the concerns I have about adding the script to github.com/InsightSoftwareConsortium/ITK.git is that it would trigger another CI run with each revision. Which seems like a waste of energy to me, because the CI does not test the script at all. Would it be possible for the CI to bypass changes in ITK/Utilities/Maintenance ?

@dzenanz
Copy link
Member

dzenanz commented Feb 8, 2023

I don't know whether it is possible to run the CI conditionally (I don't think it is), and if so how to do it.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Feb 8, 2023

I don't know whether it is possible to run the CI conditionally (I don't think it is), and if so how to do it.

Oh wait, I see now at https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/trigger?view=azure-pipelines#trigger-batch-branches-paths-tags


trigger:
  batch: true
  branches:
    include:
    - features/*
    exclude:
    - features/experimental/*
  paths:
    exclude:
    - README.md

So it seems possible to exclude "README.md" from the CI trigger. Then also any other file, I guess.

@dzenanz
Copy link
Member

dzenanz commented Feb 8, 2023

You could give it a try, exclude Utilities/Maintenance before submitting a PR with the new script.

@dzenanz dzenanz merged commit 5c97b76 into InsightSoftwareConsortium:master Feb 8, 2023
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 8, 2023
Added in-class `{}` default member initializers to data members of classes
that have a destructor declared `override = default`.

Follow-up to pull request InsightSoftwareConsortium#3913
commit 5c97b76
"STYLE: Add in-class `{}` initializers to classes with virtual functions"
dzenanz pushed a commit that referenced this pull request Feb 13, 2023
Added in-class `{}` default member initializers to data members of classes
that have a destructor declared `override = default`.

Follow-up to pull request #3913
commit 5c97b76
"STYLE: Add in-class `{}` initializers to classes with virtual functions"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 23, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 23, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 25, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 25, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 25, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 25, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Mar 1, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"

pull request InsightSoftwareConsortium#3941
"STYLE: Add in-class `{}` member initializers to 3-letter data members"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Mar 4, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"

pull request InsightSoftwareConsortium#3941
"STYLE: Add in-class `{}` member initializers to 3-letter data members"

pull request InsightSoftwareConsortium#3945
"STYLE: Add in-class `{}` member initializers having trailing comments"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Mar 6, 2023
The script that was used for the following pull requests:

pull request InsightSoftwareConsortium#3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request InsightSoftwareConsortium#3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request InsightSoftwareConsortium#3917
"STYLE: Add in-class `{}` initializers to classes with override = default"

pull request InsightSoftwareConsortium#3941
"STYLE: Add in-class `{}` member initializers to 3-letter data members"

pull request InsightSoftwareConsortium#3945
"STYLE: Add in-class `{}` member initializers having trailing comments"
dzenanz pushed a commit that referenced this pull request Mar 20, 2023
The script that was used for the following pull requests:

pull request #3851
"STYLE: Add in-class `{}` member initializers to objects created by New()"

pull request #3913
"STYLE: Add in-class `{}` initializers to classes with virtual functions"

pull request #3917
"STYLE: Add in-class `{}` initializers to classes with override = default"

pull request #3941
"STYLE: Add in-class `{}` member initializers to 3-letter data members"

pull request #3945
"STYLE: Add in-class `{}` member initializers having trailing comments"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Bridge Issues affecting the Bridge module area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Numerics Issues affecting the Numerics module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module type:Style Style changes: no logic impact (indentation, comments, naming)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants