Apply Clang-Tidy readability-container-size-empty (#93236)

Not only is this change usually shorter and more readable, it also can yield better performance. size() is not always a constant time operation (such as on LinkedLists), but empty() always is.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/93236
Approved by: https://github.com/malfet
This commit is contained in:
Aaron Gokaslan
2023-01-29 23:28:19 +00:00
committed by PyTorch MergeBot
parent 239afa0e43
commit 0247ed27cc
216 changed files with 518 additions and 525 deletions

View File

@ -503,7 +503,7 @@ RangeValue::RangeValue(
}
Graph& g = *m.graph();
if (inputs.size() == 0) {
if (inputs.empty()) {
throw ErrorReport(loc) << "range expected at least 1 arguments, got 0";
} else if (inputs.size() == 1) {
end_ = inputs[0];
@ -613,7 +613,7 @@ void IterableTree::addChild(
GraphFunction& m,
const SugaredValuePtr& iter_value) {
c10::optional<int64_t> child_len = iter_value->staticLen();
if (children_.size() == 0) {
if (children_.empty()) {
unroll_length_ = child_len;
} else {
if ((unroll_length_ && !child_len) || (child_len && !unroll_length_)) {
@ -637,7 +637,7 @@ std::shared_ptr<SugaredValue> MagicMethod::call(
at::ArrayRef<NamedValue> args,
at::ArrayRef<NamedValue> kwargs,
size_t n_binders) {
if (args.size() > 0) {
if (!args.empty()) {
Value* self = args[0].value(*m.graph());
if (auto class_ptr = self->type()->cast<ClassType>()) {
return SimpleValue(self)