Skip to content

Commit 4f6bdcb

Browse files
N-Dekkerhjmjohnson
authored andcommitted
STYLE: Replace T var; var = x with T var = x for types from std
For Standard Library types that have a non-trivial default-constructor and a non-trivial assignment operator, `T var = x` is typically slightly faster than `T var; var = x`. Otherwise it's just a matter of style. Using Notepad++, Replace in Files, doing: Find what: ^( [ ]+)(std::[^ ]*)([ ]+)(\w+);[\r\n]+\1\4\ = Replace with: $1$2$3$4 = Filters: itk*.* Directory: D:\src\ITK\Modules [v] Match case (*) Regular expression Follow-up to pull request InsightSoftwareConsortium#4932 commit 5b121f4 "STYLE: Replace `T var; var = x` with `T var = x` for arithmetic types"
1 parent 5375056 commit 4f6bdcb

File tree

11 files changed

+22
-47
lines changed

11 files changed

+22
-47
lines changed

Modules/Core/Common/test/itkLineIteratorTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ itkLineIteratorTest(int argc, char * argv[])
114114
endIndex.Fill(189);
115115
LineIteratorType it(output, startIndex, endIndex);
116116

117-
std::vector<IndexType>::iterator itBaseline;
118-
itBaseline = baselineIndex.begin();
117+
std::vector<IndexType>::iterator itBaseline = baselineIndex.begin();
119118
while (!it.IsAtEnd())
120119
{
121120
it.Set(255);

Modules/Core/GPUCommon/src/itkOpenCLUtil.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ GetValidTypename(const std::type_info & intype, const std::vector<std::string> &
443443
{
444444
std::string typestr = GetTypename(intype);
445445
bool isValid = false;
446-
std::vector<std::string>::const_iterator validPos;
447-
validPos = std::find(validtypes.begin(), validtypes.end(), typestr);
446+
std::vector<std::string>::const_iterator validPos = std::find(validtypes.begin(), validtypes.end(), typestr);
448447
if (validPos != validtypes.end())
449448
{
450449
isValid = true;

Modules/IO/CSV/test/itkCSVArray2DFileReaderTest.cxx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
207207
}
208208

209209
// Test Row Names
210-
std::vector<std::string> test_row_names;
211-
test_row_names = dfo->GetRowHeaders();
210+
std::vector<std::string> test_row_names = dfo->GetRowHeaders();
212211

213212
std::vector<std::string> row_names;
214213
row_names.emplace_back("Jan");
@@ -225,8 +224,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
225224
PrintVector(test_row_names);
226225

227226
// Test Column Names
228-
std::vector<std::string> test_col_names;
229-
test_col_names = dfo->GetColumnHeaders();
227+
std::vector<std::string> test_col_names = dfo->GetColumnHeaders();
230228

231229
std::vector<std::string> col_names;
232230
col_names.emplace_back("Africa");
@@ -244,8 +242,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
244242

245243

246244
// Test a row (using index access)
247-
std::vector<double> test_row_1;
248-
test_row_1 = dfo->GetRow(1);
245+
std::vector<double> test_row_1 = dfo->GetRow(1);
249246

250247
std::vector<double> row_1;
251248
row_1.push_back(99);
@@ -262,8 +259,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
262259
PrintVector(test_row_1);
263260

264261
// Test a row (using string access)
265-
std::vector<double> test_row_Jan;
266-
test_row_Jan = dfo->GetRow("Jan");
262+
std::vector<double> test_row_Jan = dfo->GetRow("Jan");
267263

268264
std::vector<double> row_Jan;
269265
row_Jan.push_back(nan);
@@ -281,8 +277,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
281277
PrintVector(test_row_Jan);
282278

283279
// Test a column (using index)
284-
std::vector<double> test_col_2;
285-
test_col_2 = dfo->GetColumn(2);
280+
std::vector<double> test_col_2 = dfo->GetColumn(2);
286281

287282
std::vector<double> col_2;
288283
col_2.push_back(5);
@@ -299,8 +294,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
299294
PrintVector(col_2);
300295

301296
// Test a column (using string access)
302-
std::vector<double> test_col_Africa;
303-
test_col_Africa = dfo->GetColumn("Africa");
297+
std::vector<double> test_col_Africa = dfo->GetColumn("Africa");
304298

305299
std::vector<double> col_Africa;
306300
col_Africa.push_back(nan);
@@ -319,8 +313,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
319313
// Test a row that does not exist
320314
try
321315
{
322-
std::vector<double> test_row_Oct;
323-
test_row_Oct = dfo->GetRow("Oct");
316+
std::vector<double> test_row_Oct = dfo->GetRow("Oct");
324317
if (!test_row_Oct.empty())
325318
{
326319
std::cerr << "Row should be empty! Test Failed!";
@@ -336,8 +329,7 @@ itkCSVArray2DFileReaderTest(int argc, char * argv[])
336329
try
337330
{
338331
// Test column that does not exist
339-
std::vector<double> test_col_Eur;
340-
test_col_Eur = dfo->GetColumn("Eur");
332+
std::vector<double> test_col_Eur = dfo->GetColumn("Eur");
341333
if (!test_col_Eur.empty())
342334
{
343335
std::cerr << "Column should be empty! Test Failed!";

Modules/IO/ImageBase/src/itkArchetypeSeriesFileNames.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ ArchetypeSeriesFileNames::Scan()
183183
fit->NumericSortOn();
184184
names = fit->GetFileNames();
185185

186-
std::vector<std::string>::iterator ait;
187-
ait = std::find(names.begin(), names.end(), pathPrefix + unixArchetype);
186+
std::vector<std::string>::iterator ait = std::find(names.begin(), names.end(), pathPrefix + unixArchetype);
188187

189188
// Accept the list if it contains the archetype and is not the
190189
// "trivial" list (containing only the archetype)

Modules/IO/MINC/src/itkMINCImageIO.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,7 @@ MINCImageIO::ReadImageInformation()
760760
{
761761
mitype_t att_data_type;
762762
size_t att_length;
763-
std::string entry_key;
764-
765-
entry_key = group_name;
763+
std::string entry_key = group_name;
766764
entry_key += ":";
767765
entry_key += attribute;
768766

Modules/IO/NIFTI/test/itkNiftiImageIOTest.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ MakeNiftiImage(const char * filename)
169169
}
170170
catch (const itk::ExceptionObject & ex)
171171
{
172-
std::string message;
173-
message = "Problem found while writing image ";
172+
std::string message = "Problem found while writing image ";
174173
message += filename;
175174
message += "\n";
176175
message += ex.GetLocation();
@@ -359,8 +358,7 @@ TestImageOfSymMats(const std::string & fname)
359358
}
360359
catch (const itk::ExceptionObject & ex)
361360
{
362-
std::string message;
363-
message = "Problem found while writing image ";
361+
std::string message = "Problem found while writing image ";
364362
message += fname;
365363
message += "\n";
366364
message += ex.GetLocation();
@@ -379,8 +377,7 @@ TestImageOfSymMats(const std::string & fname)
379377
}
380378
catch (const itk::ExceptionObject & ex)
381379
{
382-
std::string message;
383-
message = "Problem found while reading image ";
380+
std::string message = "Problem found while reading image ";
384381
message += fname;
385382
message += "\n";
386383
message += ex.GetLocation();

Modules/IO/NIFTI/test/itkNiftiImageIOTest3.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ TestImageOfVectors(const std::string & fname, const std::string & intentCode = "
156156
}
157157
catch (const itk::ExceptionObject & ex)
158158
{
159-
std::string message;
160-
message = "Problem found while writing image ";
159+
std::string message = "Problem found while writing image ";
161160
message += fname;
162161
message += "\n";
163162
message += ex.GetLocation();
@@ -176,8 +175,7 @@ TestImageOfVectors(const std::string & fname, const std::string & intentCode = "
176175
}
177176
catch (const itk::ExceptionObject & ex)
178177
{
179-
std::string message;
180-
message = "Problem found while reading image ";
178+
std::string message = "Problem found while reading image ";
181179
message += fname;
182180
message += "\n";
183181
message += ex.GetLocation();

Modules/IO/NIFTI/test/itkNiftiImageIOTest4.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ itkNiftiImageIOTest4(int argc, char * argv[])
110110
}
111111
catch (const itk::ExceptionObject & ex)
112112
{
113-
std::string message;
114-
message = "Problem found while writing image ";
113+
std::string message = "Problem found while writing image ";
115114
message += fname;
116115
message += "\n";
117116
message += ex.GetLocation();
@@ -130,8 +129,7 @@ itkNiftiImageIOTest4(int argc, char * argv[])
130129
}
131130
catch (const itk::ExceptionObject & ex)
132131
{
133-
std::string message;
134-
message = "Problem found while reading image ";
132+
std::string message = "Problem found while reading image ";
135133
message += fname;
136134
message += "\n";
137135
message += ex.GetLocation();

Modules/IO/XML/test/itkDOMTest6.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ testStringToolsWithItkArray()
328328
void
329329
testStringToolsForStringOperations()
330330
{
331-
std::string s;
332-
333-
s = " Hello World! ";
331+
std::string s = " Hello World! ";
334332
if (itk::StringTools::TrimLeft(s) != "Hello World! ")
335333
{
336334
throw "testStringToolsForStringOperations: failed trimming left";

Modules/Numerics/NarrowBand/test/itkNarrowBandTest.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ itkNarrowBandTest(int, char *[])
6565
}
6666

6767
// Split the band
68-
std::vector<RegionType> regions;
69-
regions = band->SplitBand(10);
68+
std::vector<RegionType> regions = band->SplitBand(10);
7069
// RegionType region;
7170
using regionitType = std::vector<RegionType>::const_iterator;
7271
regionitType regionsit = regions.begin();

0 commit comments

Comments
 (0)