From e1f2e3f0d7f9a91445842c5ce8f20388818584ba Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 30 Sep 2025 09:22:25 +0000 Subject: [PATCH] Remove unneeded string_view_migration --- ortools/base/BUILD.bazel | 6 ---- ortools/base/string_view_migration.h | 34 ------------------- ortools/linear_solver/wrappers/BUILD.bazel | 1 - .../wrappers/model_builder_helper.cc | 14 +++----- ortools/math_opt/core/BUILD.bazel | 1 - ortools/math_opt/core/model_summary.h | 4 +-- ortools/math_opt/cpp/BUILD.bazel | 2 -- ortools/math_opt/cpp/model_test.cc | 4 +-- ortools/math_opt/cpp/solve_result.cc | 3 +- .../cpp/streamable_solver_init_arguments.cc | 8 ++--- ortools/math_opt/elemental/BUILD.bazel | 1 - .../elemental/elemental_from_proto.cc | 4 +-- ortools/sat/BUILD.bazel | 1 - ortools/sat/cp_model.cc | 7 ++-- ortools/sat/python/BUILD.bazel | 1 - ortools/sat/python/cp_model_helper.cc | 1 - ortools/sat/python/linear_expr.cc | 3 +- 17 files changed, 15 insertions(+), 80 deletions(-) delete mode 100644 ortools/base/string_view_migration.h diff --git a/ortools/base/BUILD.bazel b/ortools/base/BUILD.bazel index df1f2d88e1..fa1d98a29d 100644 --- a/ortools/base/BUILD.bazel +++ b/ortools/base/BUILD.bazel @@ -449,12 +449,6 @@ cc_library( ], ) -cc_library( - name = "string_view_migration", - hdrs = ["string_view_migration.h"], - deps = ["@abseil-cpp//absl/strings"], -) - cc_library( name = "strong_int", hdrs = ["strong_int.h"], diff --git a/ortools/base/string_view_migration.h b/ortools/base/string_view_migration.h deleted file mode 100644 index 85f5b1f495..0000000000 --- a/ortools/base/string_view_migration.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2010-2025 Google LLC -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ORTOOLS_BASE_STRING_VIEW_MIGRATION_H_ -#define ORTOOLS_BASE_STRING_VIEW_MIGRATION_H_ - -#include - -#include "absl/strings/string_view.h" - -// This file contains helpers for various string_view migration efforts. These -// are not intended to be stable long-term. - -namespace google::protobuf { - -inline std::string StringCopy(absl::string_view str) { - return std::string(str); -} - -inline std::string StringCopy(const std::string& str) { return str; } - -} // namespace google::protobuf - -#endif // ORTOOLS_BASE_STRING_VIEW_MIGRATION_H_ diff --git a/ortools/linear_solver/wrappers/BUILD.bazel b/ortools/linear_solver/wrappers/BUILD.bazel index 8d8018afa3..8705fab14c 100644 --- a/ortools/linear_solver/wrappers/BUILD.bazel +++ b/ortools/linear_solver/wrappers/BUILD.bazel @@ -30,7 +30,6 @@ cc_library( ], deps = [ "//ortools/base:file", - "//ortools/base:string_view_migration", "//ortools/linear_solver", "//ortools/linear_solver:gurobi_util", "//ortools/linear_solver:linear_solver_cc_proto", diff --git a/ortools/linear_solver/wrappers/model_builder_helper.cc b/ortools/linear_solver/wrappers/model_builder_helper.cc index 610d158a42..64e810c118 100644 --- a/ortools/linear_solver/wrappers/model_builder_helper.cc +++ b/ortools/linear_solver/wrappers/model_builder_helper.cc @@ -30,7 +30,6 @@ #include "absl/strings/str_join.h" #include "ortools/base/helpers.h" #include "ortools/base/options.h" -#include "ortools/base/string_view_migration.h" #include "ortools/linear_solver/gurobi_util.h" #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" @@ -184,7 +183,7 @@ double ModelBuilderHelper::VarObjectiveCoefficient(int var_index) const { } std::string ModelBuilderHelper::VarName(int var_index) const { - return google::protobuf::StringCopy(model_.variable(var_index).name()); + return model_.variable(var_index).name(); } int ModelBuilderHelper::AddLinearConstraint() { @@ -260,7 +259,7 @@ double ModelBuilderHelper::ConstraintUpperBound(int ct_index) const { } std::string ModelBuilderHelper::ConstraintName(int ct_index) const { - return google::protobuf::StringCopy(model_.constraint(ct_index).name()); + return model_.constraint(ct_index).name(); } std::vector ModelBuilderHelper::ConstraintVarIndices(int ct_index) const { @@ -400,8 +399,7 @@ double ModelBuilderHelper::EnforcedConstraintUpperBound(int ct_index) const { std::string ModelBuilderHelper::EnforcedConstraintName(int ct_index) const { DCHECK(IsEnforcedConstraint(ct_index)); - return google::protobuf::StringCopy( - model_.general_constraint(ct_index).name()); + return model_.general_constraint(ct_index).name(); } std::vector ModelBuilderHelper::EnforcedConstraintVarIndices( @@ -438,9 +436,7 @@ int ModelBuilderHelper::num_constraints() const { return model_.constraint_size() + model_.general_constraint_size(); } -std::string ModelBuilderHelper::name() const { - return google::protobuf::StringCopy(model_.name()); -} +std::string ModelBuilderHelper::name() const { return model_.name(); } void ModelBuilderHelper::SetName(const std::string& name) { model_.set_name(name); @@ -745,7 +741,7 @@ double ModelSolverHelper::activity(int ct_index) { std::string ModelSolverHelper::status_string() const { if (!has_response()) return ""; - return google::protobuf::StringCopy(response_.value().status_str()); + return response_.value().status_str(); } double ModelSolverHelper::wall_time() const { diff --git a/ortools/math_opt/core/BUILD.bazel b/ortools/math_opt/core/BUILD.bazel index 2e23d864e8..e819d100ab 100644 --- a/ortools/math_opt/core/BUILD.bazel +++ b/ortools/math_opt/core/BUILD.bazel @@ -64,7 +64,6 @@ cc_library( deps = [ "//ortools/base:linked_hash_map", "//ortools/base:status_macros", - "//ortools/base:string_view_migration", "//ortools/math_opt:model_cc_proto", "//ortools/math_opt:model_update_cc_proto", "@abseil-cpp//absl/algorithm:container", diff --git a/ortools/math_opt/core/model_summary.h b/ortools/math_opt/core/model_summary.h index 9c481a3998..061000751e 100644 --- a/ortools/math_opt/core/model_summary.h +++ b/ortools/math_opt/core/model_summary.h @@ -32,7 +32,6 @@ #include "absl/types/span.h" #include "ortools/base/linked_hash_map.h" #include "ortools/base/status_macros.h" -#include "ortools/base/string_view_migration.h" #include "ortools/math_opt/model.pb.h" #include "ortools/math_opt/model_update.pb.h" @@ -257,8 +256,7 @@ absl::Status UpdateBiMapFromMappedData( } absl::c_sort(new_ids); for (const int64_t id : new_ids) { - RETURN_IF_ERROR(bimap.Insert( - id, google::protobuf::StringCopy(proto_map.at(id).name()))); + RETURN_IF_ERROR(bimap.Insert(id, proto_map.at(id).name())); } return absl::OkStatus(); } diff --git a/ortools/math_opt/cpp/BUILD.bazel b/ortools/math_opt/cpp/BUILD.bazel index b56d33eed8..88ac229c0c 100644 --- a/ortools/math_opt/cpp/BUILD.bazel +++ b/ortools/math_opt/cpp/BUILD.bazel @@ -374,7 +374,6 @@ cc_library( ":variable_and_expressions", "//ortools/base:protoutil", "//ortools/base:status_macros", - "//ortools/base:string_view_migration", "//ortools/math_opt:result_cc_proto", "//ortools/math_opt:solution_cc_proto", "//ortools/math_opt/core:math_opt_proto_utils", @@ -605,7 +604,6 @@ cc_library( srcs = ["streamable_solver_init_arguments.cc"], hdrs = ["streamable_solver_init_arguments.h"], deps = [ - "//ortools/base:string_view_migration", "//ortools/math_opt:parameters_cc_proto", "//ortools/math_opt/solvers:gurobi_cc_proto", "@abseil-cpp//absl/status:statusor", diff --git a/ortools/math_opt/cpp/model_test.cc b/ortools/math_opt/cpp/model_test.cc index 1ae84a2391..83b1ebb713 100644 --- a/ortools/math_opt/cpp/model_test.cc +++ b/ortools/math_opt/cpp/model_test.cc @@ -32,7 +32,6 @@ #include "gtest/gtest.h" #include "ortools/base/gmock.h" #include "ortools/base/parse_text_proto.h" -#include "ortools/base/string_view_migration.h" #include "ortools/math_opt/constraints/indicator/indicator_constraint.h" #include "ortools/math_opt/constraints/quadratic/quadratic_constraint.h" #include "ortools/math_opt/constraints/second_order_cone/second_order_cone_constraint.h" @@ -600,8 +599,7 @@ std::vector SortedValueNames( const google::protobuf::Map& messages) { std::vector> sorted_entries; for (const auto& [id, message] : messages) { - sorted_entries.push_back( - {id, google::protobuf::StringCopy(message.name())}); + sorted_entries.push_back({id, message.name()}); } absl::c_sort(sorted_entries); std::vector result; diff --git a/ortools/math_opt/cpp/solve_result.cc b/ortools/math_opt/cpp/solve_result.cc index caf28a4e75..ae0cab0da0 100644 --- a/ortools/math_opt/cpp/solve_result.cc +++ b/ortools/math_opt/cpp/solve_result.cc @@ -33,7 +33,6 @@ #include "absl/types/span.h" #include "ortools/base/protoutil.h" #include "ortools/base/status_macros.h" -#include "ortools/base/string_view_migration.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" #include "ortools/math_opt/cpp/linear_constraint.h" #include "ortools/math_opt/cpp/variable_and_expressions.h" @@ -374,7 +373,7 @@ absl::StatusOr Termination::FromProto( return absl::InvalidArgumentError("reason must be specified"); } Termination result(/*is_maximize=*/false, *reason, - google::protobuf::StringCopy(termination_proto.detail())); + termination_proto.detail()); result.limit = EnumFromProto(termination_proto.limit()); OR_ASSIGN_OR_RETURN3( result.problem_status, diff --git a/ortools/math_opt/cpp/streamable_solver_init_arguments.cc b/ortools/math_opt/cpp/streamable_solver_init_arguments.cc index e2248fa306..3d0eea1b74 100644 --- a/ortools/math_opt/cpp/streamable_solver_init_arguments.cc +++ b/ortools/math_opt/cpp/streamable_solver_init_arguments.cc @@ -16,7 +16,6 @@ #include #include "absl/status/statusor.h" -#include "ortools/base/string_view_migration.h" #include "ortools/math_opt/parameters.pb.h" #include "ortools/math_opt/solvers/gurobi.pb.h" @@ -35,11 +34,10 @@ GurobiInitializerProto::ISVKey GurobiISVKey::Proto() const { GurobiISVKey GurobiISVKey::FromProto( const GurobiInitializerProto::ISVKey& key_proto) { return GurobiISVKey{ - .name = google::protobuf::StringCopy(key_proto.name()), - .application_name = - google::protobuf::StringCopy(key_proto.application_name()), + .name = key_proto.name(), + .application_name = key_proto.application_name(), .expiration = key_proto.expiration(), - .key = google::protobuf::StringCopy(key_proto.key()), + .key = key_proto.key(), }; } diff --git a/ortools/math_opt/elemental/BUILD.bazel b/ortools/math_opt/elemental/BUILD.bazel index 8b1c2de959..d0e9163fb6 100644 --- a/ortools/math_opt/elemental/BUILD.bazel +++ b/ortools/math_opt/elemental/BUILD.bazel @@ -62,7 +62,6 @@ cc_library( ":symmetry", ":thread_safe_id_map", "//ortools/base:status_macros", - "//ortools/base:string_view_migration", "//ortools/math_opt:model_cc_proto", "//ortools/math_opt:model_update_cc_proto", "//ortools/math_opt:sparse_containers_cc_proto", diff --git a/ortools/math_opt/elemental/elemental_from_proto.cc b/ortools/math_opt/elemental/elemental_from_proto.cc index 313b24f432..50f5afa087 100644 --- a/ortools/math_opt/elemental/elemental_from_proto.cc +++ b/ortools/math_opt/elemental/elemental_from_proto.cc @@ -26,7 +26,6 @@ #include "google/protobuf/repeated_ptr_field.h" #include "ortools/base/status_builder.h" #include "ortools/base/status_macros.h" -#include "ortools/base/string_view_migration.h" #include "ortools/math_opt/core/model_summary.h" #include "ortools/math_opt/elemental/attr_key.h" #include "ortools/math_opt/elemental/attributes.h" @@ -254,8 +253,7 @@ absl::StatusOr ElementalFromModelProtoImpl(const ModelProto& proto) { return absl::UnimplementedError( "Elemental does not support sos2 constraints yet"); } - Elemental elemental(google::protobuf::StringCopy(proto.name()), - google::protobuf::StringCopy(proto.objective().name())); + Elemental elemental(proto.name(), proto.objective().name()); AddVariables(proto.variables(), elemental); { const ObjectiveProto& objective = proto.objective(); diff --git a/ortools/sat/BUILD.bazel b/ortools/sat/BUILD.bazel index abacf5ec82..bd646ee91f 100644 --- a/ortools/sat/BUILD.bazel +++ b/ortools/sat/BUILD.bazel @@ -35,7 +35,6 @@ cc_library( ":cp_model_utils", ":model", ":sat_parameters_cc_proto", - "//ortools/base:string_view_migration", "//ortools/util:sorted_interval_list", "@abseil-cpp//absl/container:flat_hash_map", "@abseil-cpp//absl/log:check", diff --git a/ortools/sat/cp_model.cc b/ortools/sat/cp_model.cc index ff19e87aae..30a888d3d8 100644 --- a/ortools/sat/cp_model.cc +++ b/ortools/sat/cp_model.cc @@ -26,7 +26,6 @@ #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" -#include "ortools/base/string_view_migration.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_utils.h" #include "ortools/util/sorted_interval_list.h" @@ -126,8 +125,7 @@ IntVar IntVar::WithName(absl::string_view name) { std::string IntVar::Name() const { if (builder_ == nullptr) return "null"; - return google::protobuf::StringCopy( - builder_->Proto().variables(index_).name()); + return builder_->Proto().variables(index_).name(); } ::operations_research::Domain IntVar::Domain() const { @@ -621,8 +619,7 @@ BoolVar IntervalVar::PresenceBoolVar() const { std::string IntervalVar::Name() const { if (builder_ == nullptr) return "null"; - return google::protobuf::StringCopy( - builder_->Proto().constraints(index_).name()); + return builder_->Proto().constraints(index_).name(); } std::string IntervalVar::DebugString() const { diff --git a/ortools/sat/python/BUILD.bazel b/ortools/sat/python/BUILD.bazel index 302c08eb8b..c10627f620 100644 --- a/ortools/sat/python/BUILD.bazel +++ b/ortools/sat/python/BUILD.bazel @@ -31,7 +31,6 @@ cc_library( srcs = ["linear_expr.cc"], hdrs = ["linear_expr.h"], deps = [ - "//ortools/base:string_view_migration", "//ortools/sat:cp_model_cc_proto", "//ortools/sat:cp_model_utils", "//ortools/util:fp_roundtrip_conv", diff --git a/ortools/sat/python/cp_model_helper.cc b/ortools/sat/python/cp_model_helper.cc index 854b187f95..5ccd55c846 100644 --- a/ortools/sat/python/cp_model_helper.cc +++ b/ortools/sat/python/cp_model_helper.cc @@ -30,7 +30,6 @@ #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" -#include "ortools/base/string_view_migration.h" #include "ortools/port/proto_utils.h" // IWYU: keep #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_utils.h" diff --git a/ortools/sat/python/linear_expr.cc b/ortools/sat/python/linear_expr.cc index 309c8f8d14..61f899437e 100644 --- a/ortools/sat/python/linear_expr.cc +++ b/ortools/sat/python/linear_expr.cc @@ -27,7 +27,6 @@ #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" -#include "ortools/base/string_view_migration.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_utils.h" #include "ortools/util/fp_roundtrip_conv.h" @@ -800,7 +799,7 @@ std::string IntVar::name() const { if (model_proto_ == nullptr || index_ >= model_proto_->variables_size()) { return ""; } - return google::protobuf::StringCopy(model_proto_->variables(index_).name()); + return model_proto_->variables(index_).name(); } void IntVar::SetName(absl::string_view name) {