Skip to content

Commit

Permalink
[clang-tidy] No.37 enable performance-faster-string-find (#56255)
Browse files Browse the repository at this point in the history
  • Loading branch information
enkilee authored Aug 15, 2023
1 parent 4526f61 commit baf2ffa
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/details/nan_inf_utils_detail.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions paddle/fluid/framework/ir/fusion_group/code_generator_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/op_call_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/jit/property.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/jit/serializer_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/api/lib/op_meta_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions paddle/phi/core/enforce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit baf2ffa

Please sign in to comment.