From baf2ffaf5cebcbc5d0c0b05610663ec86dcf0d19 Mon Sep 17 00:00:00 2001 From: cyberslack_lee Date: Tue, 15 Aug 2023 14:24:31 +0800 Subject: [PATCH] [clang-tidy] No.37 enable performance-faster-string-find (#56255) --- .clang-tidy | 2 +- .../fluid/framework/details/nan_inf_utils_detail.cc | 2 +- .../ir/fusion_group/code_generator_helper.cc | 12 ++++++------ paddle/fluid/framework/op_call_stack.cc | 2 +- paddle/fluid/jit/property.cc | 2 +- paddle/fluid/jit/serializer_utils.cc | 4 ++-- paddle/phi/api/lib/op_meta_info.cc | 2 +- paddle/phi/core/enforce.cc | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a3847a6ec11..518fb18aca0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -188,7 +188,7 @@ modernize-use-nullptr, modernize-use-override, -modernize-use-transparent-functors, -modernize-use-uncaught-exceptions, --performance-faster-string-find, +performance-faster-string-find, -performance-for-range-copy, -performance-implicit-conversion-in-loop, -performance-inefficient-algorithm, diff --git a/paddle/fluid/framework/details/nan_inf_utils_detail.cc b/paddle/fluid/framework/details/nan_inf_utils_detail.cc index 54cc8049553..6c3f5356ac1 100644 --- a/paddle/fluid/framework/details/nan_inf_utils_detail.cc +++ b/paddle/fluid/framework/details/nan_inf_utils_detail.cc @@ -141,7 +141,7 @@ static void InitWhiteListFormEnv() { std::stringstream ss(op_var_skip); std::string op_var; while (std::getline(ss, op_var, ',')) { - auto pos = op_var.find(":"); + auto pos = op_var.find(':'); PADDLE_ENFORCE_EQ( pos != std::string::npos, true, diff --git a/paddle/fluid/framework/ir/fusion_group/code_generator_helper.cc b/paddle/fluid/framework/ir/fusion_group/code_generator_helper.cc index 8441b1e02f9..fdf5530e89d 100644 --- a/paddle/fluid/framework/ir/fusion_group/code_generator_helper.cc +++ b/paddle/fluid/framework/ir/fusion_group/code_generator_helper.cc @@ -34,12 +34,12 @@ static T StringTo(const std::string& str) { static std::string ExpandMultivariateTemplate(const std::string& rhs, const size_t input_size) { - int start_pos = rhs.find("[", 0); - int end_pos = rhs.find("]", 0); + int start_pos = rhs.find('[', 0); + int end_pos = rhs.find(']', 0); std::string sum_rhs = rhs.substr(0, start_pos); std::string repeated_component = rhs.substr(start_pos + 1, (end_pos - start_pos - 1)); - int replace_pos = repeated_component.find("?", 0); + int replace_pos = repeated_component.find('?', 0); for (size_t i = 1; i < input_size; i++) { std::string append_str = repeated_component; @@ -64,9 +64,9 @@ static std::string RefineTemplateWithAttr(const std::string& op_type, // Get attr with different type, Now we only support the simple attr // condition std::string attr_name, default_value; - if (exp_definition.find("=") != std::string::npos) { - attr_name = exp_definition.substr(0, exp_definition.find("=")); - default_value = exp_definition.substr(exp_definition.rfind("=") + 1, + if (exp_definition.find('=') != std::string::npos) { + attr_name = exp_definition.substr(0, exp_definition.find('=')); + default_value = exp_definition.substr(exp_definition.rfind('=') + 1, exp_definition.length() - 1); ret = default_value; } else { diff --git a/paddle/fluid/framework/op_call_stack.cc b/paddle/fluid/framework/op_call_stack.cc index 3c3f93975f7..b9a7aad1fdf 100644 --- a/paddle/fluid/framework/op_call_stack.cc +++ b/paddle/fluid/framework/op_call_stack.cc @@ -25,7 +25,7 @@ std::string InsertIndentationIntoEachLine(const std::string &str) { std::ostringstream sout; size_t start_pos = 0; size_t end_pos = 0; - while ((end_pos = str.find_first_of("\n", start_pos)) != std::string::npos) { + while ((end_pos = str.find_first_of('\n', start_pos)) != std::string::npos) { sout << " " << str.substr(start_pos, end_pos - start_pos + 1); start_pos = end_pos + 1; } diff --git a/paddle/fluid/jit/property.cc b/paddle/fluid/jit/property.cc index b0c943b24a6..174b3b065f1 100644 --- a/paddle/fluid/jit/property.cc +++ b/paddle/fluid/jit/property.cc @@ -86,7 +86,7 @@ std::unordered_map> Property::Values() { if (entry.has_name()) { auto &n = entry.name(); // remove Class Name suffix - auto key = n.substr(n.find_first_of(".") + 1); + auto key = n.substr(n.find_first_of('.') + 1); std::shared_ptr var(new Variable()); auto type = entry.type(); switch (type) { diff --git a/paddle/fluid/jit/serializer_utils.cc b/paddle/fluid/jit/serializer_utils.cc index 2899fb97f73..5b58b9d4173 100644 --- a/paddle/fluid/jit/serializer_utils.cc +++ b/paddle/fluid/jit/serializer_utils.cc @@ -70,12 +70,12 @@ const std::vector> PdmodelFilePaths( std::string format_path = path; ReplaceAll(&format_path, R"(\\)", "/"); ReplaceAll(&format_path, R"(\)", "/"); - if (format_path.find("/") == std::string::npos) { + if (format_path.find('/') == std::string::npos) { format_path = "./" + format_path; } std::string layer_name = - format_path.substr(format_path.find_last_of("/") + 1); + format_path.substr(format_path.find_last_of('/') + 1); std::string dir_path = format_path.substr(0, format_path.length() - layer_name.length()); DIR* dir = opendir(dir_path.c_str()); diff --git a/paddle/phi/api/lib/op_meta_info.cc b/paddle/phi/api/lib/op_meta_info.cc index 9e4085fe1cb..5d0e2f139c2 100644 --- a/paddle/phi/api/lib/op_meta_info.cc +++ b/paddle/phi/api/lib/op_meta_info.cc @@ -39,7 +39,7 @@ std::string trim_spaces(const std::string& str) { } std::vector ParseAttrStr(const std::string& attr) { - auto split_pos = attr.find_first_of(":"); + auto split_pos = attr.find_first_of(':'); PADDLE_ENFORCE_NE(split_pos, std::string::npos, phi::errors::InvalidArgument( diff --git a/paddle/phi/core/enforce.cc b/paddle/phi/core/enforce.cc index 44b138eaa43..69bcbf91ef4 100644 --- a/paddle/phi/core/enforce.cc +++ b/paddle/phi/core/enforce.cc @@ -176,7 +176,7 @@ void ThrowWarnInternal(const std::string& msg) { std::string SimplifyErrorTypeFormat(const std::string& str) { std::ostringstream sout; - size_t type_end_pos = str.find(":", 0); + size_t type_end_pos = str.find(':', 0); if (type_end_pos == std::string::npos) { sout << str; } else { @@ -278,7 +278,7 @@ std::string GetExternalErrorMsg(T status) { Dl_info info; if (dladdr(reinterpret_cast(GetCurrentTraceBackString), &info)) { std::string phi_so_path(info.dli_fname); - const size_t last_slash_idx = phi_so_path.find_last_of("/"); + const size_t last_slash_idx = phi_so_path.find_last_of('/'); if (std::string::npos != last_slash_idx) { phi_so_path.erase(last_slash_idx, std::string::npos); } -- GitLab