Skip to content

Commit

Permalink
Merge pull request #2181 from MaximSmolskiy/fix_cppcheck_performance_…
Browse files Browse the repository at this point in the history
…passedByValue_warnings

Fix cppcheck performance passedByValue warnings
  • Loading branch information
jajhall authored Feb 15, 2025
2 parents 4c783d9 + 7e79b8a commit 1bbc7df
Show file tree
Hide file tree
Showing 32 changed files with 109 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/Highs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1631,8 +1631,8 @@ class Highs {
const HighsInt original_num_col, const HighsInt original_num_row,
const std::vector<double>& original_col_cost,
const std::vector<double>& original_col_lower,
const std::vector<double> original_col_upper,
const std::vector<HighsVarType> original_integrality);
const std::vector<double>& original_col_upper,
const std::vector<HighsVarType>& original_integrality);
HighsStatus elasticityFilter(const double global_lower_penalty,
const double global_upper_penalty,
const double global_rhs_penalty,
Expand Down
6 changes: 3 additions & 3 deletions src/highs_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ HighsStatus highs_mipPostsolve(Highs* h, const HighsSolution& solution) {
return h->postsolve(solution);
}

HighsStatus highs_writeSolution(Highs* h, const std::string filename,
HighsStatus highs_writeSolution(Highs* h, const std::string& filename,
const HighsInt style) {
return h->writeSolution(filename, style);
}
Expand Down Expand Up @@ -838,7 +838,7 @@ std::tuple<HighsStatus, std::string> highs_getColName(Highs* h,
}

std::tuple<HighsStatus, int> highs_getColByName(Highs* h,
const std::string name) {
const std::string& name) {
HighsInt col;
HighsStatus status = h->getColByName(name, col);
return std::make_tuple(status, col);
Expand All @@ -852,7 +852,7 @@ std::tuple<HighsStatus, std::string> highs_getRowName(Highs* h,
}

std::tuple<HighsStatus, int> highs_getRowByName(Highs* h,
const std::string name) {
const std::string& name) {
HighsInt row;
HighsStatus status = h->getRowByName(name, row);
return std::make_tuple(status, row);
Expand Down
6 changes: 3 additions & 3 deletions src/io/Filereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static inline void tolower(std::string& s) {
[](unsigned char c) { return std::tolower(c); });
}

static const std::string getFilenameExt(const std::string filename) {
static const std::string getFilenameExt(const std::string& filename) {
// Extract file name extension
std::string name = filename;
std::size_t found = name.find_last_of(".");
Expand Down Expand Up @@ -71,7 +71,7 @@ Filereader* Filereader::getFilereader(const HighsLogOptions& log_options,
}

void interpretFilereaderRetcode(const HighsLogOptions& log_options,
const std::string filename,
const std::string& filename,
const FilereaderRetcode code) {
switch (code) {
case FilereaderRetcode::kOk:
Expand All @@ -95,7 +95,7 @@ void interpretFilereaderRetcode(const HighsLogOptions& log_options,
}
}

std::string extractModelName(const std::string filename) {
std::string extractModelName(const std::string& filename) {
// Extract model name
std::string name = filename;
std::size_t found = name.find_last_of("/\\");
Expand Down
4 changes: 2 additions & 2 deletions src/io/Filereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ enum class FilereaderRetcode {
};

void interpretFilereaderRetcode(const HighsLogOptions& log_options,
const std::string filename,
const std::string& filename,
const FilereaderRetcode code);
std::string extractModelName(const std::string filename);
std::string extractModelName(const std::string& filename);

class Filereader {
public:
Expand Down
10 changes: 5 additions & 5 deletions src/io/HMPSIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using std::map;
// Read file called filename. Returns 0 if OK and 1 if file can't be opened
//
FilereaderRetcode readMps(
const HighsLogOptions& log_options, const std::string filename,
const HighsLogOptions& log_options, const std::string& filename,
HighsInt mxNumRow, HighsInt mxNumCol, HighsInt& numRow, HighsInt& numCol,
ObjSense& objSense, double& objOffset, vector<HighsInt>& Astart,
vector<HighsInt>& Aindex, vector<double>& Avalue, vector<double>& colCost,
Expand Down Expand Up @@ -537,7 +537,7 @@ bool load_mpsLine(std::istream& file, HighsVarType& integerVar, HighsInt lmax,
}

HighsStatus writeModelAsMps(const HighsOptions& options,
const std::string filename, const HighsModel& model,
const std::string& filename, const HighsModel& model,
const bool free_format) {
bool warning_found = false;
const HighsLp& lp = model.lp_;
Expand Down Expand Up @@ -603,16 +603,16 @@ HighsStatus writeModelAsMps(const HighsOptions& options,
}

HighsStatus writeMps(
const HighsLogOptions& log_options, const std::string filename,
const std::string model_name, const HighsInt& num_row,
const HighsLogOptions& log_options, const std::string& filename,
const std::string& model_name, const HighsInt& num_row,
const HighsInt& num_col, const HighsInt& q_dim, const ObjSense& sense,
const double& offset, const vector<double>& col_cost,
const vector<double>& col_lower, const vector<double>& col_upper,
const vector<double>& row_lower, const vector<double>& row_upper,
const vector<HighsInt>& a_start, const vector<HighsInt>& a_index,
const vector<double>& a_value, const vector<HighsInt>& q_start,
const vector<HighsInt>& q_index, const vector<double>& q_value,
const vector<HighsVarType>& integrality, const std::string objective_name,
const vector<HighsVarType>& integrality, const std::string& objective_name,
const vector<std::string>& col_names, const vector<std::string>& row_names,
const bool use_free_format) {
HighsInt num_no_cost_zero_columns = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/io/HMPSIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const HighsInt field_6_start = 49;
const HighsInt field_6_width = 12;

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

HighsStatus writeMps(
const HighsLogOptions& log_options, const std::string filename,
const std::string model_name, const HighsInt& num_row,
const HighsLogOptions& log_options, const std::string& filename,
const std::string& model_name, const HighsInt& num_row,
const HighsInt& num_col, const HighsInt& q_dim, const ObjSense& sense,
const double& offset, const vector<double>& col_cost,
const vector<double>& col_lower, const vector<double>& col_upper,
const vector<double>& row_lower, const vector<double>& row_upper,
const vector<HighsInt>& a_start, const vector<HighsInt>& a_index,
const vector<double>& a_value, const vector<HighsInt>& q_start,
const vector<HighsInt>& q_index, const vector<double>& q_value,
const vector<HighsVarType>& integrality, std::string objective_name,
const vector<HighsVarType>& integrality, const std::string& objective_name,
const vector<std::string>& col_names, const vector<std::string>& row_names,
const bool use_free_format = true);

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

HighsStatus writeModelAsMps(const HighsOptions& options,
const std::string filename, const HighsModel& model,
const std::string& filename, const HighsModel& model,
const bool free = true);

#endif /* IO_HMPSIO_H_ */
6 changes: 3 additions & 3 deletions src/io/HighsIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
}

void highsReportDevInfo(const HighsLogOptions* log_options,
const std::string line) {
const std::string& line) {
if (log_options) {
highsLogDev(*log_options, HighsLogType::kInfo, "%s", line.c_str());
} else {
printf("%s", line.c_str());
}
}

void highsOpenLogFile(HighsOptions& options, const std::string log_file) {
void highsOpenLogFile(HighsOptions& options, const std::string& log_file) {
highsOpenLogFile(options.log_options, options.records, log_file);
}

Expand Down Expand Up @@ -275,7 +275,7 @@ const std::string highsBoolToString(const bool b, const HighsInt field_width) {
return b ? " true" : "false";
}

const std::string highsInsertMdEscapes(const std::string from_string) {
const std::string highsInsertMdEscapes(const std::string& from_string) {
std::string to_string = "";
const char* underscore = "_";
const char* backslash = "\\";
Expand Down
6 changes: 3 additions & 3 deletions src/io/HighsIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ void highsFprintfString(FILE* file, const HighsLogOptions& log_options_,
* indicated by null pointer
*/
void highsReportDevInfo(const HighsLogOptions* log_options,
const std::string line);
const std::string& line);

void highsOpenLogFile(HighsOptions& options, const std::string log_file);
void highsOpenLogFile(HighsOptions& options, const std::string& log_file);

void highsReportLogOptions(const HighsLogOptions& log_options_);

Expand All @@ -109,6 +109,6 @@ std::string highsFormatToString(const char* format, ...);
const std::string highsBoolToString(const bool b,
const HighsInt field_width = 2);

const std::string highsInsertMdEscapes(const std::string from_string);
const std::string highsInsertMdEscapes(const std::string& from_string);

#endif
2 changes: 1 addition & 1 deletion src/io/LoadOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specified.
HighsLoadOptionsStatus loadOptionsFromFile(
const HighsLogOptions& report_log_options, HighsOptions& options,
const std::string filename) {
const std::string& filename) {
if (filename.size() == 0) return HighsLoadOptionsStatus::kEmpty;

string line, option, value;
Expand Down
2 changes: 1 addition & 1 deletion src/io/LoadOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ enum class HighsLoadOptionsStatus { kError = -1, kOk = 0, kEmpty = 1 };
// For extended options to be parsed from filename
HighsLoadOptionsStatus loadOptionsFromFile(
const HighsLogOptions& report_log_options, HighsOptions& options,
const std::string filename);
const std::string& filename);

#endif
2 changes: 1 addition & 1 deletion src/ipm/IpxWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ HighsStatus reportIpxIpmCrossoverStatus(const HighsOptions& options,
}

bool ipxStatusError(const bool status_error, const HighsOptions& options,
std::string message, const int value) {
const std::string& message, const int value) {
if (status_error) {
if (value < 0) {
highsLogUser(options.log_options, HighsLogType::kError, "Ipx: %s\n",
Expand Down
2 changes: 1 addition & 1 deletion src/ipm/IpxWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ HighsStatus reportIpxIpmCrossoverStatus(const HighsOptions& options,
const bool ipm_status);

bool ipxStatusError(const bool status_error, const HighsOptions& options,
std::string message, const int value = -1);
const std::string& message, const int value = -1);

bool illegalIpxSolvedStatus(const ipx::Info& ipx_info,
const HighsOptions& options);
Expand Down
4 changes: 2 additions & 2 deletions src/lp_data/Highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ HighsStatus Highs::readModel(const std::string& filename) {
reader->readModelFromFile(options_, filename, model);
delete reader;
if (call_code != FilereaderRetcode::kOk) {
interpretFilereaderRetcode(options_.log_options, filename.c_str(),
interpretFilereaderRetcode(options_.log_options, filename,
call_code);
return_status =
interpretCallStatus(options_.log_options, HighsStatus::kError,
Expand Down Expand Up @@ -2567,7 +2567,7 @@ HighsStatus Highs::changeColsIntegrality(const HighsInt from_col,
}

static HighsStatus analyseSetCreateError(HighsLogOptions log_options,
const std::string method,
const std::string& method,
const HighsInt create_error,
const bool ordered,
const HighsInt num_set_entries,
Expand Down
4 changes: 2 additions & 2 deletions src/lp_data/HighsDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ HighsDebugStatus debugWorseStatus(const HighsDebugStatus status0,
std::max((HighsInt)status0, (HighsInt)status1));
}

bool debugVectorRightSize(const std::vector<double> v,
bool debugVectorRightSize(const std::vector<double>& v,
const HighsInt right_size) {
const HighsInt v_size = v.size();
const bool is_right_size = v_size == right_size;
assert(is_right_size);
return is_right_size;
}

bool debugVectorRightSize(const std::vector<HighsInt> v,
bool debugVectorRightSize(const std::vector<HighsInt>& v,
const HighsInt right_size) {
const HighsInt v_size = v.size();
const bool is_right_size = v_size == right_size;
Expand Down
4 changes: 2 additions & 2 deletions src/lp_data/HighsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ HighsStatus debugDebugToHighsStatus(const HighsDebugStatus debug_status);
HighsDebugStatus debugWorseStatus(const HighsDebugStatus status0,
const HighsDebugStatus status1);

bool debugVectorRightSize(const std::vector<double> v,
bool debugVectorRightSize(const std::vector<double>& v,
const HighsInt right_size);

bool debugVectorRightSize(const std::vector<HighsInt> v,
bool debugVectorRightSize(const std::vector<HighsInt>& v,
const HighsInt right_size);

#endif // SIMPLEX_HIGHSDEBUG_H_
2 changes: 1 addition & 1 deletion src/lp_data/HighsIis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::string HighsIis::iisBoundStatusToString(HighsInt bound_status) const {
return "*****";
}

void HighsIis::report(const std::string message, const HighsLp& lp) const {
void HighsIis::report(const std::string& message, const HighsLp& lp) const {
HighsInt num_iis_col = this->col_index_.size();
HighsInt num_iis_row = this->row_index_.size();
if (num_iis_col > 10 || num_iis_row > 10) return;
Expand Down
2 changes: 1 addition & 1 deletion src/lp_data/HighsIis.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HighsIis {

void invalidate();
std::string iisBoundStatusToString(HighsInt bound_status) const;
void report(const std::string message, const HighsLp& lp) const;
void report(const std::string& message, const HighsLp& lp) const;
void addCol(const HighsInt col, const HighsInt status = kIisBoundStatusNull);
void addRow(const HighsInt row, const HighsInt status = kIisBoundStatusNull);
void removeCol(const HighsInt col);
Expand Down
6 changes: 3 additions & 3 deletions src/lp_data/HighsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,8 +2027,8 @@ HighsStatus Highs::elasticityFilterReturn(
const HighsInt original_num_col, const HighsInt original_num_row,
const std::vector<double>& original_col_cost,
const std::vector<double>& original_col_lower,
const std::vector<double> original_col_upper,
const std::vector<HighsVarType> original_integrality) {
const std::vector<double>& original_col_upper,
const std::vector<HighsVarType>& original_integrality) {
const HighsLp& lp = this->model_.lp_;
double objective_function_value = info_.objective_function_value;
// Delete any additional rows and columns, and restore the original
Expand Down Expand Up @@ -3466,7 +3466,7 @@ bool Highs::infeasibleBoundsOk() {
HighsInt num_ok_infeasible_bound = 0;
const bool has_integrality = lp.integrality_.size() > 0;
// Lambda for assessing infeasible bounds
auto assessInfeasibleBound = [&](const std::string type, const HighsInt iX,
auto assessInfeasibleBound = [&](const std::string& type, const HighsInt iX,
double& lower, double& upper) {
double range = upper - lower;
if (range >= 0) return true;
Expand Down
12 changes: 6 additions & 6 deletions src/lp_data/HighsLpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ HighsStatus assessLp(HighsLp& lp, const HighsOptions& options) {
return return_status;
}

bool lpDimensionsOk(std::string message, const HighsLp& lp,
bool lpDimensionsOk(const std::string& message, const HighsLp& lp,
const HighsLogOptions& log_options) {
bool ok = true;
const HighsInt num_col = lp.num_col_;
Expand Down Expand Up @@ -683,7 +683,7 @@ void relaxSemiVariables(HighsLp& lp, bool& made_semi_variable_mods) {
}

bool activeModifiedUpperBounds(const HighsOptions& options, const HighsLp& lp,
const std::vector<double> col_value) {
const std::vector<double>& col_value) {
const std::vector<HighsInt>& tightened_semi_variable_upper_bound_index =
lp.mods_.save_tightened_semi_variable_upper_bound_index;
const HighsInt num_tightened_upper =
Expand Down Expand Up @@ -1947,7 +1947,7 @@ void reportLpColMatrix(const HighsLogOptions& log_options, const HighsLp& lp) {
}
}

void reportMatrix(const HighsLogOptions& log_options, const std::string message,
void reportMatrix(const HighsLogOptions& log_options, const std::string& message,
const HighsInt num_col, const HighsInt num_nz,
const HighsInt* start, const HighsInt* index,
const double* value) {
Expand Down Expand Up @@ -2033,7 +2033,7 @@ void analyseLp(const HighsLogOptions& log_options, const HighsLp& lp) {
lp.row_upper_);
}

HighsStatus readSolutionFile(const std::string filename,
HighsStatus readSolutionFile(const std::string& filename,
const HighsOptions& options, HighsLp& lp,
HighsBasis& basis, HighsSolution& solution,
const HighsInt style) {
Expand Down Expand Up @@ -2378,7 +2378,7 @@ void assessColPrimalSolution(const HighsOptions& options, const double primal,

// Determine validity, primal feasibility and (when relevant) integer
// feasibility of a solution
HighsStatus assessLpPrimalSolution(const std::string message,
HighsStatus assessLpPrimalSolution(const std::string& message,
const HighsOptions& options,
const HighsLp& lp,
const HighsSolution& solution, bool& valid,
Expand Down Expand Up @@ -2532,7 +2532,7 @@ void writeBasisFile(FILE*& file, const HighsBasis& basis) {
}

HighsStatus readBasisFile(const HighsLogOptions& log_options, HighsBasis& basis,
const std::string filename) {
const std::string& filename) {
// Opens a basis file as an ifstream
HighsStatus return_status = HighsStatus::kOk;
std::ifstream in_file;
Expand Down
Loading

0 comments on commit 1bbc7df

Please sign in to comment.