Use ContainsValue() instead of std::find() in tools/ BUG=561800 Review-Url: https://codereview.chromium.org/2938163003 Cr-Original-Commit-Position: refs/heads/master@{#480018} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 3e0d5228e24db43bb266c19ed82782be7239bb9b
diff --git a/tools/gn/action_target_generator.cc b/tools/gn/action_target_generator.cc index 5c7cbf6..b7efa43 100644 --- a/tools/gn/action_target_generator.cc +++ b/tools/gn/action_target_generator.cc
@@ -4,6 +4,7 @@ #include "tools/gn/action_target_generator.h" +#include "base/stl_util.h" #include "tools/gn/build_settings.h" #include "tools/gn/err.h" #include "tools/gn/filesystem_utils.h" @@ -73,10 +74,8 @@ // together. const auto& required_args_substitutions = target_->action_values().args().required_types(); - bool has_rsp_file_name = std::find(required_args_substitutions.begin(), - required_args_substitutions.end(), - SUBSTITUTION_RSP_FILE_NAME) != - required_args_substitutions.end(); + bool has_rsp_file_name = base::ContainsValue(required_args_substitutions, + SUBSTITUTION_RSP_FILE_NAME); if (target_->action_values().uses_rsp_file() && !has_rsp_file_name) { *err_ = Err(function_call_, "Missing {{response_file_name}} in args.", "This target defines response_file_contents but doesn't use\n"
diff --git a/tools/gn/function_process_file_template.cc b/tools/gn/function_process_file_template.cc index 28e3e46..47de640 100644 --- a/tools/gn/function_process_file_template.cc +++ b/tools/gn/function_process_file_template.cc
@@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/stl_util.h" #include "tools/gn/functions.h" #include "tools/gn/parse_tree.h" #include "tools/gn/scope.h" @@ -94,8 +95,7 @@ } auto& types = subst.required_types(); - if (std::find(types.begin(), types.end(), - SUBSTITUTION_SOURCE_TARGET_RELATIVE) != types.end()) { + if (base::ContainsValue(types, SUBSTITUTION_SOURCE_TARGET_RELATIVE)) { *err = Err(template_arg, "Not a valid substitution type for the function."); return Value(); }
diff --git a/tools/gn/runtime_deps_unittest.cc b/tools/gn/runtime_deps_unittest.cc index d0658f4..7de91fc 100644 --- a/tools/gn/runtime_deps_unittest.cc +++ b/tools/gn/runtime_deps_unittest.cc
@@ -4,8 +4,7 @@ #include <stddef.h> -#include <algorithm> - +#include "base/stl_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "tools/gn/runtime_deps.h" #include "tools/gn/scheduler.h" @@ -91,29 +90,25 @@ EXPECT_TRUE(MakePair("./main", &main) == result[0]); // The rest of the ordering is undefined. First the data files. - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../stat.dat", &stat)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../shared.dat", &shared)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../loadable.dat", &loadable)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../set.dat", &set)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../main.dat", &main)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("../../stat.dat", &stat))) + << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../shared.dat", &shared))) + << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../loadable.dat", &loadable))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("../../set.dat", &set))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("../../main.dat", &main))) + << GetVectorDescription(result); // Check the static library and loadable module. - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("./libshared.so", &shared)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("./libloadable.so", &loadable)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("./libshared.so", &shared))) + << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("./libloadable.so", &loadable))) + << GetVectorDescription(result); } // Tests that executables that aren't listed as data deps aren't included in @@ -163,12 +158,11 @@ EXPECT_TRUE(MakePair("./main", &main) == result[0]); // The rest of the ordering is undefined. - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("./datadep", &datadep)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../final_in.dat", &final_in)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("./datadep", &datadep))) + << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../final_in.dat", &final_in))) + << GetVectorDescription(result); } // Tests that action and copy outputs are considered if they're data deps, but @@ -232,24 +226,23 @@ EXPECT_TRUE(MakePair("./main", &main) == result[0]); // The rest of the ordering is undefined. - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../datadep.data", &datadep)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../datadep_copy.data", &datadep_copy)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../datadep.output", &datadep)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../datadep_copy.output", &datadep_copy)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../dep.data", &dep)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../dep_copy/data/", &dep_copy)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../datadep.data", &datadep))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue( + result, MakePair("../../datadep_copy.data", &datadep_copy))) + << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../datadep.output", &datadep))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue( + result, MakePair("../../datadep_copy.output", &datadep_copy))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("../../dep.data", &dep))) + << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../dep_copy/data/", &dep_copy))) + << GetVectorDescription(result); // Explicitly asking for the runtime deps of an action target only includes // the data and not all outputs. @@ -344,19 +337,16 @@ // The rest of the ordering is undefined. // The framework bundle's internal dependencies should not be incldued. - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("Bundle.framework/", &bundle)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("Bundle.framework/", &bundle))) + << GetVectorDescription(result); // But direct data and data dependencies should be. - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("./datadep", &data_dep)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../dd.data", &data_dep)) != - result.end()) << GetVectorDescription(result); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../b.data", &bundle)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("./datadep", &data_dep))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("../../dd.data", &data_dep))) + << GetVectorDescription(result); + EXPECT_TRUE(base::ContainsValue(result, MakePair("../../b.data", &bundle))) + << GetVectorDescription(result); } // Tests that a dependency duplicated in regular and data deps is processed @@ -380,9 +370,9 @@ // The results should be the executable and the copy output. std::vector<std::pair<OutputFile, const Target*>> result = ComputeRuntimeDeps(&target); - EXPECT_TRUE(std::find(result.begin(), result.end(), - MakePair("../../action.output", &action)) != - result.end()) << GetVectorDescription(result); + EXPECT_TRUE( + base::ContainsValue(result, MakePair("../../action.output", &action))) + << GetVectorDescription(result); } // Tests that actions can't have output substitutions.
diff --git a/tools/gn/target.cc b/tools/gn/target.cc index 759d7bf..f8af715 100644 --- a/tools/gn/target.cc +++ b/tools/gn/target.cc
@@ -6,9 +6,8 @@ #include <stddef.h> -#include <algorithm> - #include "base/bind.h" +#include "base/stl_util.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "tools/gn/config_values_extractors.h" @@ -95,8 +94,7 @@ Toolchain::ToolType tool_type; if (!target->GetOutputFilesForSource(source, &tool_type, &source_outputs)) continue; - if (std::find(source_outputs.begin(), source_outputs.end(), file) != - source_outputs.end()) + if (base::ContainsValue(source_outputs, file)) return true; } }