Skip to content

Commit

Permalink
【Hackathon 6th Fundable Projects 2 No.42】performance-inefficient-stri…
Browse files Browse the repository at this point in the history
…ng-concatenation-final (#63779)

* restore

* restore

* useless commit

* restore
  • Loading branch information
walkalone20 authored May 22, 2024
1 parent fa8b4f3 commit 492dfa1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
53 changes: 35 additions & 18 deletions paddle/common/flags_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,13 @@ void Flag::SetValueFromString(const std::string& value) {
void FlagRegistry::RegisterFlag(Flag* flag) {
auto iter = flags_.find(flag->name_);
if (iter != flags_.end()) {
LOG_FLAG_FATAL_ERROR("flag multiple definition, flag \"" + flag->name_ +
"\" was defined both in " + iter->second->file_ +
" and " + flag->file_);
std::string error_msg = "flag multiple definition, flag \"";
error_msg += flag->name_;
error_msg += "\" was defined both in ";
error_msg += iter->second->file_;
error_msg += " and ";
error_msg += flag->file_;
LOG_FLAG_FATAL_ERROR(error_msg);
} else {
std::lock_guard<std::mutex> lock(mutex_);
flags_[flag->name_] = flag;
Expand Down Expand Up @@ -425,8 +429,11 @@ TEST_API void ParseCommandLineFlags(int* pargc, char*** pargv) {
// the argv format is "--name" or "--name value"
name = argv.substr(hyphen_num);
if (name.empty()) {
LOG_FLAG_FATAL_ERROR("invalid commandline argument: \"" + argv +
"\", " + arg_format_help);
std::string error_msg = "invalid commandline argument: \"";
error_msg += argv;
error_msg += "\", ";
error_msg += arg_format_help;
LOG_FLAG_FATAL_ERROR(error_msg);
}

// print help message
Expand All @@ -437,16 +444,21 @@ TEST_API void ParseCommandLineFlags(int* pargc, char*** pargv) {

// get the value from next argv.
if (++i == argv_num) {
LOG_FLAG_FATAL_ERROR("expected value of flag \"" + name +
"\" but found none.");
std::string error_msg = "expected value of flag \"";
error_msg += name;
error_msg += "\" but found none.";
LOG_FLAG_FATAL_ERROR(error_msg);
} else {
value = argvs[i];
}
} else {
// the argv format is "--name=value"
if (split_pos == hyphen_num || split_pos == argv.size() - 1) {
LOG_FLAG_FATAL_ERROR("invalid commandline argument: \"" + argv +
"\", " + arg_format_help);
std::string error_msg = "invalid commandline argument: \"";
error_msg += argv;
error_msg += "\", ";
error_msg += arg_format_help;
LOG_FLAG_FATAL_ERROR(error_msg);
}
name = argv.substr(hyphen_num, split_pos - hyphen_num);
value = argv.substr(split_pos + 1);
Expand All @@ -468,8 +480,10 @@ TEST_API void ParseCommandLineFlags(int* pargc, char*** pargv) {
if (value.back() == '"') {
value.pop_back();
} else {
LOG_FLAG_FATAL_ERROR("unexperted end of flag \"" + name +
"\" value while looking for matching `\"'");
std::string error_msg = "unexperted end of flag \"";
error_msg += name;
error_msg += "\" value while looking for matching `\"'";
LOG_FLAG_FATAL_ERROR(error_msg);
}
}
}
Expand Down Expand Up @@ -509,13 +523,16 @@ T GetFromEnv(const std::string& name, const T& default_val) {
flag.SetValueFromString(value_str);
if (!ErrorStream().str().empty()) {
ErrorStream().str("");
LOG_FLAG_FATAL_ERROR("value \"" + value_str +
"\" of environment"
"variable \"" +
name +
"\" is invalid when "
"using GetFromEnv with " +
FlagType2String(type) + " type.");
std::string error_msg = "value \"";
error_msg += value_str;
error_msg += "\" of environment";
error_msg += "variable \"";
error_msg += name;
error_msg += "\" is invalid when ";
error_msg += "using GetFromEnv with ";
error_msg += FlagType2String(type);
error_msg += " type.";
LOG_FLAG_FATAL_ERROR(error_msg);
}
return value;
} else {
Expand Down
10 changes: 7 additions & 3 deletions paddle/fluid/framework/ir/fusion_group/code_generator_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static std::string ExpandMultivariateTemplate(const std::string& rhs,
for (size_t i = 1; i < input_size; i++) {
std::string append_str = repeated_component;
append_str.replace(replace_pos, 1, std::to_string(i));
sum_rhs = sum_rhs + append_str;
sum_rhs += append_str;
}
return sum_rhs;
}
Expand Down Expand Up @@ -171,8 +171,12 @@ std::string OperationExpression::GetRHS(std::unordered_set<int>* used,
length++;
}
std::string number_str = rhs.substr(pos + 2, length);
if (rhs_type_ == "__half")
number_str = "__float2half(" + number_str + ")";
if (rhs_type_ == "__half") {
std::string temp_str = "__float2half(";
temp_str += number_str;
temp_str += ")";
number_str = temp_str;
}
rhs.replace(pos, length + 3, number_str);
pos = pos + number_str.length();
}
Expand Down

0 comments on commit 492dfa1

Please # to comment.