[BE]: Enable clang-tidy check for readability-string-compare (#115994)

Adds a clang-tidy check to ensure string compare is not used unnecessarily in a way that is less efficient and less readable if an equality overload exists.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/115994
Approved by: https://github.com/albanD
This commit is contained in:
Aaron Gokaslan
2023-12-18 16:13:00 +00:00
committed by PyTorch MergeBot
parent d7caef7996
commit 647f14e70b
2 changed files with 3 additions and 2 deletions

View File

@ -52,6 +52,7 @@ modernize-*,
-modernize-use-nodiscard,
performance-*,
readability-container-size-empty,
readability-string-compare,
'
HeaderFilterRegex: '^(aten/|c10/|torch/).*$'
AnalyzeTemporaryDtors: false

View File

@ -243,7 +243,7 @@ struct CollectiveFingerPrint {
// Check op type
auto other_op = opTypeToString(other.op_type_);
auto this_op = opTypeToString(op_type_);
if (other_op.compare(this_op) != 0) {
if (other_op != this_op) {
found_diff = true;
ss << c10::str(" Op type: ", this_op, "vs ", other_op);
}
@ -258,7 +258,7 @@ struct CollectiveFingerPrint {
return;
}
for (size_t i = 0; i < other.size(); ++i) {
if (other[i].compare(curr[i]) != 0) {
if (other[i] != curr[i]) {
found_diff = true;
ss << c10::str(" Tensor ", arg, ": ", curr, "vs ", other);
return;