Skip to content

Commit 4d0b4e4

Browse files
authored
Merge pull request #2833 from ERGO-Code/check-2181
Check 2181: pass all `std::string` by reference
2 parents 80b16ef + 48487c6 commit 4d0b4e4

32 files changed

+122
-118
lines changed

highs/Highs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ class Highs {
17471747
const HighsInt original_num_col, const HighsInt original_num_row,
17481748
const std::vector<double>& original_col_cost,
17491749
const std::vector<double>& original_col_lower,
1750-
const std::vector<double> original_col_upper,
1751-
const std::vector<HighsVarType> original_integrality);
1750+
const std::vector<double>& original_col_upper,
1751+
const std::vector<HighsVarType>& original_integrality);
17521752
HighsStatus elasticityFilter(const double global_lower_penalty,
17531753
const double global_upper_penalty,
17541754
const double global_rhs_penalty,

highs/highs_bindings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ HighsStatus highs_mipPostsolve(Highs* h, const HighsSolution& solution) {
177177
return h->postsolve(solution);
178178
}
179179

180-
HighsStatus highs_writeSolution(Highs* h, const std::string filename,
180+
HighsStatus highs_writeSolution(Highs* h, const std::string& filename,
181181
const HighsInt style) {
182182
return h->writeSolution(filename, style);
183183
}
@@ -905,7 +905,7 @@ std::tuple<HighsStatus, std::string> highs_getColName(Highs* h,
905905
}
906906

907907
std::tuple<HighsStatus, int> highs_getColByName(Highs* h,
908-
const std::string name) {
908+
const std::string& name) {
909909
HighsInt col;
910910
HighsStatus status = h->getColByName(name, col);
911911
return std::make_tuple(status, col);
@@ -919,7 +919,7 @@ std::tuple<HighsStatus, std::string> highs_getRowName(Highs* h,
919919
}
920920

921921
std::tuple<HighsStatus, int> highs_getRowByName(Highs* h,
922-
const std::string name) {
922+
const std::string& name) {
923923
HighsInt row;
924924
HighsStatus status = h->getRowByName(name, row);
925925
return std::make_tuple(status, row);

highs/io/Filereader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static inline void tolower(std::string& s) {
2121
[](unsigned char c) { return std::tolower(c); });
2222
}
2323

24-
static const std::string getFilenameExt(const std::string filename) {
24+
static const std::string getFilenameExt(const std::string& filename) {
2525
// Extract file name extension
2626
std::string name = filename;
2727
std::size_t found = name.find_last_of(".");
@@ -71,7 +71,7 @@ Filereader* Filereader::getFilereader(const HighsLogOptions& log_options,
7171
}
7272

7373
void interpretFilereaderRetcode(const HighsLogOptions& log_options,
74-
const std::string filename,
74+
const std::string& filename,
7575
const FilereaderRetcode code) {
7676
switch (code) {
7777
case FilereaderRetcode::kOk:
@@ -96,7 +96,7 @@ void interpretFilereaderRetcode(const HighsLogOptions& log_options,
9696
}
9797
}
9898

99-
std::string extractModelName(const std::string filename) {
99+
std::string extractModelName(const std::string& filename) {
100100
// Extract model name
101101
std::string name = filename;
102102
std::size_t found = name.find_last_of("/\\");

highs/io/Filereader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ enum class FilereaderRetcode {
2525
};
2626

2727
void interpretFilereaderRetcode(const HighsLogOptions& log_options,
28-
const std::string filename,
28+
const std::string& filename,
2929
const FilereaderRetcode code);
30-
std::string extractModelName(const std::string filename);
30+
std::string extractModelName(const std::string& filename);
3131

3232
class Filereader {
3333
public:

highs/io/HMPSIO.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using std::map;
3030
// Read file called filename. Returns 0 if OK and 1 if file can't be opened
3131
//
3232
FilereaderRetcode readMps(
33-
const HighsLogOptions& log_options, const std::string filename,
33+
const HighsLogOptions& log_options, const std::string& filename,
3434
HighsInt mxNumRow, HighsInt mxNumCol, HighsInt& numRow, HighsInt& numCol,
3535
ObjSense& objSense, double& objOffset, vector<HighsInt>& Astart,
3636
vector<HighsInt>& Aindex, vector<double>& Avalue, vector<double>& colCost,
@@ -549,8 +549,8 @@ bool load_mpsLine(std::istream& file, HighsVarType& integerVar, HighsInt lmax,
549549
}
550550

551551
HighsStatus writeModelAsMps(const HighsOptions& options,
552-
const std::string filename, const HighsModel& model,
553-
const bool free_format) {
552+
const std::string& filename,
553+
const HighsModel& model, const bool free_format) {
554554
bool warning_found = false;
555555
const HighsLp& lp = model.lp_;
556556

@@ -593,16 +593,16 @@ HighsStatus writeModelAsMps(const HighsOptions& options,
593593
}
594594

595595
HighsStatus writeMps(
596-
const HighsLogOptions& log_options, const std::string filename,
597-
const std::string model_name, const HighsInt& num_row,
596+
const HighsLogOptions& log_options, const std::string& filename,
597+
const std::string& model_name, const HighsInt& num_row,
598598
const HighsInt& num_col, const HighsInt& q_dim, const ObjSense& sense,
599599
const double& offset, const vector<double>& col_cost,
600600
const vector<double>& col_lower, const vector<double>& col_upper,
601601
const vector<double>& row_lower, const vector<double>& row_upper,
602602
const vector<HighsInt>& a_start, const vector<HighsInt>& a_index,
603603
const vector<double>& a_value, const vector<HighsInt>& q_start,
604604
const vector<HighsInt>& q_index, const vector<double>& q_value,
605-
const vector<HighsVarType>& integrality, const std::string objective_name,
605+
const vector<HighsVarType>& integrality, const std::string& objective_name,
606606
const vector<std::string>& col_names, const vector<std::string>& row_names,
607607
const bool use_free_format) {
608608
HighsInt num_no_cost_zero_columns = 0;

highs/io/HMPSIO.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const HighsInt field_6_start = 49;
4242
const HighsInt field_6_width = 12;
4343

4444
FilereaderRetcode readMps(
45-
const HighsLogOptions& log_options, const std::string filename,
45+
const HighsLogOptions& log_options, const std::string& filename,
4646
HighsInt mxNumRow, HighsInt mxNumCol, HighsInt& numRow, HighsInt& numCol,
4747
ObjSense& objSense, double& objOffset, vector<HighsInt>& Astart,
4848
vector<HighsInt>& Aindex, vector<double>& Avalue, vector<double>& colCost,
@@ -55,24 +55,24 @@ FilereaderRetcode readMps(
5555
const HighsInt keep_n_rows = 0);
5656

5757
HighsStatus writeMps(
58-
const HighsLogOptions& log_options, const std::string filename,
59-
const std::string model_name, const HighsInt& num_row,
58+
const HighsLogOptions& log_options, const std::string& filename,
59+
const std::string& model_name, const HighsInt& num_row,
6060
const HighsInt& num_col, const HighsInt& q_dim, const ObjSense& sense,
6161
const double& offset, const vector<double>& col_cost,
6262
const vector<double>& col_lower, const vector<double>& col_upper,
6363
const vector<double>& row_lower, const vector<double>& row_upper,
6464
const vector<HighsInt>& a_start, const vector<HighsInt>& a_index,
6565
const vector<double>& a_value, const vector<HighsInt>& q_start,
6666
const vector<HighsInt>& q_index, const vector<double>& q_value,
67-
const vector<HighsVarType>& integrality, std::string objective_name,
67+
const vector<HighsVarType>& integrality, const std::string& objective_name,
6868
const vector<std::string>& col_names, const vector<std::string>& row_names,
6969
const bool use_free_format = true);
7070

7171
bool load_mpsLine(std::istream& file, HighsVarType& integerVar, HighsInt lmax,
7272
char* line, char* flag, double* data);
7373

7474
HighsStatus writeModelAsMps(const HighsOptions& options,
75-
const std::string filename, const HighsModel& model,
76-
const bool free = true);
75+
const std::string& filename,
76+
const HighsModel& model, const bool free = true);
7777

7878
#endif /* IO_HMPSIO_H_ */

highs/io/HighsIO.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,15 @@ void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
242242
}
243243

244244
void highsReportDevInfo(const HighsLogOptions* log_options,
245-
const std::string line) {
245+
const std::string& line) {
246246
if (log_options) {
247247
highsLogDev(*log_options, HighsLogType::kInfo, "%s", line.c_str());
248248
} else {
249249
printf("%s", line.c_str());
250250
}
251251
}
252252

253-
void highsOpenLogFile(HighsOptions& options, const std::string log_file) {
253+
void highsOpenLogFile(HighsOptions& options, const std::string& log_file) {
254254
highsOpenLogFile(options.log_options, options.records, log_file);
255255
}
256256

@@ -288,7 +288,7 @@ const std::string highsBoolToString(const bool b, const HighsInt field_width) {
288288
return b ? " true" : "false";
289289
}
290290

291-
const std::string highsInsertMdEscapes(const std::string from_string) {
291+
const std::string highsInsertMdEscapes(const std::string& from_string) {
292292
std::string to_string = "";
293293
const char* underscore = "_";
294294
const char* backslash = "\\";
@@ -303,7 +303,7 @@ const std::string highsInsertMdEscapes(const std::string from_string) {
303303
return to_string;
304304
}
305305

306-
const std::string highsInsertMdId(const std::string from_string) {
306+
const std::string highsInsertMdId(const std::string& from_string) {
307307
std::string to_string = "";
308308
const char* underscore = "_";
309309
const char* hyphen = "-";

highs/io/HighsIO.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
9595
* indicated by null pointer
9696
*/
9797
void highsReportDevInfo(const HighsLogOptions* log_options,
98-
const std::string line);
98+
const std::string& line);
9999

100-
void highsOpenLogFile(HighsOptions& options, const std::string log_file);
100+
void highsOpenLogFile(HighsOptions& options, const std::string& log_file);
101101

102102
void highsReportLogOptions(const HighsLogOptions& log_options_);
103103

@@ -106,7 +106,7 @@ std::string highsFormatToString(const char* format, ...);
106106
const std::string highsBoolToString(const bool b,
107107
const HighsInt field_width = 2);
108108

109-
const std::string highsInsertMdEscapes(const std::string from_string);
110-
const std::string highsInsertMdId(const std::string from_string);
109+
const std::string highsInsertMdEscapes(const std::string& from_string);
110+
const std::string highsInsertMdId(const std::string& from_string);
111111

112112
#endif

highs/io/LoadOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specified.
1616
HighsLoadOptionsStatus loadOptionsFromFile(
1717
const HighsLogOptions& report_log_options, HighsOptions& options,
18-
const std::string filename) {
18+
const std::string& filename) {
1919
if (filename.size() == 0) return HighsLoadOptionsStatus::kEmpty;
2020

2121
string line, option, value;

highs/io/LoadOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ enum class HighsLoadOptionsStatus { kError = -1, kOk = 0, kEmpty = 1 };
1919
// For extended options to be parsed from filename
2020
HighsLoadOptionsStatus loadOptionsFromFile(
2121
const HighsLogOptions& report_log_options, HighsOptions& options,
22-
const std::string filename);
22+
const std::string& filename);
2323

2424
#endif

0 commit comments

Comments
 (0)