diff --git a/ortools/linear_solver/linear_expr.cc b/ortools/linear_solver/linear_expr.cc index fd6e69280a..244f3f2e1e 100644 --- a/ortools/linear_solver/linear_expr.cc +++ b/ortools/linear_solver/linear_expr.cc @@ -21,6 +21,7 @@ #include #include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" #include "ortools/base/logging.h" #include "ortools/linear_solver/linear_solver.h" @@ -87,7 +88,7 @@ double LinearExpr::SolutionValue() const { namespace { -void AppendTerm(const double coef, const std::string& var_name, +void AppendTerm(const double coef, absl::string_view var_name, const bool is_first, std::string* s) { if (is_first) { if (coef == 1.0) { diff --git a/ortools/linear_solver/model_exporter.cc b/ortools/linear_solver/model_exporter.cc index 6c2d9868a8..319289dcc1 100644 --- a/ortools/linear_solver/model_exporter.cc +++ b/ortools/linear_solver/model_exporter.cc @@ -28,6 +28,7 @@ #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "absl/strings/string_view.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" @@ -50,7 +51,7 @@ class LineBreaker { // - Lines are split so that their length doesn't exceed the max length; // unless a single string given to Append() exceeds that length (in which // case it will be put alone on a single unsplit line). - void Append(const std::string& s); + void Append(absl::string_view s); // Returns true if string s will fit on the current line without adding a // carriage return. @@ -70,7 +71,7 @@ class LineBreaker { std::string output_; }; -void LineBreaker::Append(const std::string& s) { +void LineBreaker::Append(absl::string_view s) { line_size_ += s.size(); if (line_size_ > max_line_size_) { line_size_ = s.size(); @@ -258,15 +259,15 @@ namespace { class NameManager { public: NameManager() : names_set_(), last_n_(1) {} - std::string MakeUniqueName(const std::string& name); + std::string MakeUniqueName(absl::string_view name); private: absl::flat_hash_set names_set_; int last_n_; }; -std::string NameManager::MakeUniqueName(const std::string& name) { - std::string result = name; +std::string NameManager::MakeUniqueName(absl::string_view name) { + std::string result(name); // Find the 'n' so that "name_n" does not already exist. int n = last_n_; while (!names_set_.insert(result).second) { diff --git a/ortools/linear_solver/wrappers/model_builder_helper.cc b/ortools/linear_solver/wrappers/model_builder_helper.cc index 77570949b3..1ae565dc8f 100644 --- a/ortools/linear_solver/wrappers/model_builder_helper.cc +++ b/ortools/linear_solver/wrappers/model_builder_helper.cc @@ -215,8 +215,8 @@ void ModelBuilderHelper::SafeAddConstraintTerm(int ct_index, int var_index, return; } } - // If we reach this point, the variable does not exist in the constraint - // yet, so we add it to the constraint as a new term. + // If we reach this point, the variable does not exist in the constraint yet, + // so we add it to the constraint as a new term. ct_proto->add_var_index(var_index); ct_proto->add_coefficient(coeff); } @@ -235,8 +235,8 @@ void ModelBuilderHelper::SetConstraintCoefficient(int ct_index, int var_index, return; } } - // If we reach this point, the variable does not exist in the constraint - // yet, so we add it to the constraint as a new term. + // If we reach this point, the variable does not exist in the constraint yet, + // so we add it to the constraint as a new term. ct_proto->add_var_index(var_index); ct_proto->add_coefficient(coeff); } @@ -328,8 +328,8 @@ void ModelBuilderHelper::SafeAddEnforcedConstraintTerm(int ct_index, return; } } - // If we reach this point, the variable does not exist in the constraint - // yet, so we add it to the constraint as a new term. + // If we reach this point, the variable does not exist in the constraint yet, + // so we add it to the constraint as a new term. ct_proto->add_var_index(var_index); ct_proto->add_coefficient(coeff); } @@ -352,8 +352,8 @@ void ModelBuilderHelper::SetEnforcedConstraintCoefficient(int ct_index, return; } } - // If we reach this point, the variable does not exist in the constraint - // yet, so we add it to the constraint as a new term. + // If we reach this point, the variable does not exist in the constraint yet, + // so we add it to the constraint as a new term. ct_proto->add_var_index(var_index); ct_proto->add_coefficient(coeff); } diff --git a/ortools/linear_solver/xpress_interface.cc b/ortools/linear_solver/xpress_interface.cc index 03d369bc8f..a11ddeceff 100644 --- a/ortools/linear_solver/xpress_interface.cc +++ b/ortools/linear_solver/xpress_interface.cc @@ -468,7 +468,7 @@ class XpressInterface : public MPSolverInterface { std::vector mutable initial_variables_basis_status_; std::vector mutable initial_constraint_basis_status_; - // Set up the right-hand side of a constraint from its lower and upper bound. + // Setup the right-hand side of a constraint from its lower and upper bound. static void MakeRhs(double lb, double ub, double& rhs, char& sense, double& range); @@ -970,7 +970,7 @@ void XpressInterface::SetVariableInteger(int var_index, bool integer) { } } -// Set up the right-hand side of a constraint. +// Setup the right-hand side of a constraint. void XpressInterface::MakeRhs(double lb, double ub, double& rhs, char& sense, double& range) { if (lb == ub) { @@ -1366,7 +1366,7 @@ void XpressInterface::ExtractNewVariables() { obj[j] = solver_->objective_->GetCoefficient(var); } - // Arrays for modifying the problem are set up. Update the index + // Arrays for modifying the problem are setup. Update the index // of variables that will get extracted now. Updating indices // _before_ the actual extraction makes things much simpler in // case we support incremental extraction. @@ -1416,7 +1416,7 @@ void XpressInterface::ExtractNewVariables() { unique_ptr cmatind(new int[nonzeros]); unique_ptr cmatval(new double[nonzeros]); - // Here is how cmatbeg[] is set up: + // Here is how cmatbeg[] is setup: // - it is initialized as // [ 0, 0, collen[0], collen[0]+collen[1], ... ] // so that cmatbeg[j+1] tells us where in cmatind[] and diff --git a/ortools/linear_solver/xpress_interface_test.cc b/ortools/linear_solver/xpress_interface_test.cc index fe2fe88030..8ffca9c291 100644 --- a/ortools/linear_solver/xpress_interface_test.cc +++ b/ortools/linear_solver/xpress_interface_test.cc @@ -741,8 +741,8 @@ TEST(XpressInterface, Write) { OBJSENSE MAXIMIZE ROWS N __OBJ___ - L R1 - L R2 + L R1 + L R2 COLUMNS C1 __OBJ___ 1 C1 R1 3