Skip to content

Commit

Permalink
absl::string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Nov 9, 2023
1 parent 553ef23 commit cdd5de3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
3 changes: 2 additions & 1 deletion ortools/constraint_solver/alldiff_cst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <vector>

#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/logging.h"
#include "ortools/base/types.h"
#include "ortools/constraint_solver/constraint_solver.h"
Expand All @@ -36,7 +37,7 @@ class BaseAllDifferent : public Constraint {
BaseAllDifferent(Solver* const s, const std::vector<IntVar*>& vars)
: Constraint(s), vars_(vars) {}
~BaseAllDifferent() override {}
std::string DebugStringInternal(const std::string& name) const {
std::string DebugStringInternal(absl::string_view name) const {
return absl::StrFormat("%s(%s)", name, JoinDebugStringPtr(vars_, ", "));
}

Expand Down
4 changes: 2 additions & 2 deletions ortools/constraint_solver/constraint_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ class Search {
solver_->Fail();
}
}
void set_search_context(const std::string& search_context) {
void set_search_context(absl::string_view search_context) {
search_context_ = search_context;
}
std::string search_context() const { return search_context_; }
Expand Down Expand Up @@ -2512,7 +2512,7 @@ std::string Solver::GetName(const PropagationBaseObject* object) {
}

void Solver::SetName(const PropagationBaseObject* object,
const std::string& name) {
absl::string_view name) {
if (parameters_.store_names() &&
GetName(object) != name) { // in particular if name.empty()
propagation_object_names_[object] = name;
Expand Down
21 changes: 11 additions & 10 deletions ortools/constraint_solver/constraint_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
#include "absl/log/check.h"
#include "absl/random/random.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "ortools/base/logging.h"
Expand Down Expand Up @@ -1060,7 +1061,7 @@ class Solver {
uint64_t fail_stamp() const;

/// Sets the current context of the search.
void set_context(const std::string& context) { context_ = context; }
void set_context(absl::string_view context) { context_ = context; }

/// Gets the current context of the search.
const std::string& context() const { return context_; }
Expand Down Expand Up @@ -1897,7 +1898,7 @@ class Solver {
/// the corresponding parameters.
void MakeFixedDurationIntervalVarArray(int count, int64_t start_min,
int64_t start_max, int64_t duration,
bool optional, const std::string& name,
bool optional, absl::string_view name,
std::vector<IntervalVar*>* array);

/// Creates a performed interval var with a fixed duration. The duration must
Expand All @@ -1917,35 +1918,35 @@ class Solver {
/// the corresponding start variables.
void MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables, int64_t duration,
const std::string& name, std::vector<IntervalVar*>* array);
absl::string_view name, std::vector<IntervalVar*>* array);

/// This method fills the vector with interval variables built with
/// the corresponding start variables.
void MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int64_t> durations, const std::string& name,
absl::Span<const int64_t> durations, absl::string_view name,
std::vector<IntervalVar*>* array);
/// This method fills the vector with interval variables built with
/// the corresponding start variables.
void MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int> durations, const std::string& name,
absl::Span<const int> durations, absl::string_view name,
std::vector<IntervalVar*>* array);

/// This method fills the vector with interval variables built with
/// the corresponding start and performed variables.
void MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int64_t> durations,
const std::vector<IntVar*>& performed_variables, const std::string& name,
const std::vector<IntVar*>& performed_variables, absl::string_view name,
std::vector<IntervalVar*>* array);

/// This method fills the vector with interval variables built with
/// the corresponding start and performed variables.
void MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int> durations,
const std::vector<IntVar*>& performed_variables, const std::string& name,
const std::vector<IntVar*>& performed_variables, absl::string_view name,
std::vector<IntervalVar*>* array);

/// Creates a fixed and performed interval.
Expand All @@ -1964,7 +1965,7 @@ class Solver {
void MakeIntervalVarArray(int count, int64_t start_min, int64_t start_max,
int64_t duration_min, int64_t duration_max,
int64_t end_min, int64_t end_max, bool optional,
const std::string& name,
absl::string_view name,
std::vector<IntervalVar*>* array);

/// Creates an interval var that is the mirror image of the given one, that
Expand Down Expand Up @@ -3206,7 +3207,7 @@ class Solver {

/// Naming
std::string GetName(const PropagationBaseObject* object);
void SetName(const PropagationBaseObject* object, const std::string& name);
void SetName(const PropagationBaseObject* object, absl::string_view name);

/// Variable indexing (note that indexing is not reversible).
/// Returns a new index for an IntVar.
Expand Down Expand Up @@ -3443,7 +3444,7 @@ class DecisionBuilder : public BaseObject {
std::vector<SearchMonitor*>* extras);
virtual void Accept(ModelVisitor* visitor) const;
#endif
void set_name(const std::string& name) { name_ = name; }
void set_name(absl::string_view name) { name_ = name; }
std::string GetName() const;

private:
Expand Down
15 changes: 8 additions & 7 deletions ortools/constraint_solver/interval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "ortools/base/logging.h"
#include "ortools/base/types.h"
Expand Down Expand Up @@ -2297,7 +2298,7 @@ IntervalVar* Solver::MakeFixedDurationIntervalVar(int64_t start_min,

void Solver::MakeFixedDurationIntervalVarArray(
int count, int64_t start_min, int64_t start_max, int64_t duration,
bool optional, const std::string& name, std::vector<IntervalVar*>* array) {
bool optional, absl::string_view name, std::vector<IntervalVar*>* array) {
CHECK_GT(count, 0);
CHECK(array != nullptr);
array->clear();
Expand Down Expand Up @@ -2342,7 +2343,7 @@ IntervalVar* Solver::MakeFixedDurationIntervalVar(

void Solver::MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables, int64_t duration,
const std::string& name, std::vector<IntervalVar*>* array) {
absl::string_view name, std::vector<IntervalVar*>* array) {
CHECK(array != nullptr);
array->clear();
for (int i = 0; i < start_variables.size(); ++i) {
Expand All @@ -2356,7 +2357,7 @@ void Solver::MakeFixedDurationIntervalVarArray(
// the corresponding start variables.
void Solver::MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int64_t> durations, const std::string& name,
absl::Span<const int64_t> durations, absl::string_view name,
std::vector<IntervalVar*>* array) {
CHECK(array != nullptr);
CHECK_EQ(start_variables.size(), durations.size());
Expand All @@ -2370,7 +2371,7 @@ void Solver::MakeFixedDurationIntervalVarArray(

void Solver::MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int> durations, const std::string& name,
absl::Span<const int> durations, absl::string_view name,
std::vector<IntervalVar*>* array) {
CHECK(array != nullptr);
CHECK_EQ(start_variables.size(), durations.size());
Expand All @@ -2385,7 +2386,7 @@ void Solver::MakeFixedDurationIntervalVarArray(
void Solver::MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int> durations,
const std::vector<IntVar*>& performed_variables, const std::string& name,
const std::vector<IntVar*>& performed_variables, absl::string_view name,
std::vector<IntervalVar*>* array) {
CHECK(array != nullptr);
array->clear();
Expand All @@ -2399,7 +2400,7 @@ void Solver::MakeFixedDurationIntervalVarArray(
void Solver::MakeFixedDurationIntervalVarArray(
const std::vector<IntVar*>& start_variables,
absl::Span<const int64_t> durations,
const std::vector<IntVar*>& performed_variables, const std::string& name,
const std::vector<IntVar*>& performed_variables, absl::string_view name,
std::vector<IntervalVar*>* array) {
CHECK(array != nullptr);
array->clear();
Expand All @@ -2425,7 +2426,7 @@ void Solver::MakeIntervalVarArray(int count, int64_t start_min,
int64_t start_max, int64_t duration_min,
int64_t duration_max, int64_t end_min,
int64_t end_max, bool optional,
const std::string& name,
absl::string_view name,
std::vector<IntervalVar*>* const array) {
CHECK_GT(count, 0);
CHECK(array != nullptr);
Expand Down

0 comments on commit cdd5de3

Please sign in to comment.