未验证 提交 baf2ffaf 编写于 作者: C cyberslack_lee 提交者: GitHub

[clang-tidy] No.37 enable performance-faster-string-find (#56255)

上级 4526f61e
......@@ -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,
......
......@@ -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,
......
......@@ -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 {
......
......@@ -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;
}
......
......@@ -86,7 +86,7 @@ std::unordered_map<std::string, std::shared_ptr<Variable>> 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<Variable> var(new Variable());
auto type = entry.type();
switch (type) {
......
......@@ -70,12 +70,12 @@ const std::vector<std::pair<std::string, std::string>> 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());
......
......@@ -39,7 +39,7 @@ std::string trim_spaces(const std::string& str) {
}
std::vector<std::string> 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(
......
......@@ -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<void*>(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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册