PERF: readability container size empty

The emptiness of a container should be checked using the empty() method
instead of the size() method. It is not guaranteed that size() is a
constant-time function, and it is generally more efficient and also
shows clearer intent to use empty(). Furthermore some containers may
implement the empty() method but not implement the size() method. Using
empty() whenever possible makes it easier to switch to another container
in the future.

SRCDIR=/Users/johnsonhj/src/jsoncpp/ #My local SRC
BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD

cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,readability-container-size-empty  -header-filter=.* -fix
This commit is contained in:
Hans Johnson
2019-01-14 17:08:51 -06:00
committed by Hans Johnson
parent d3d2e17b64
commit 3beadff472
4 changed files with 23 additions and 23 deletions

View File

@@ -880,7 +880,7 @@ bool Reader::pushError(const Value& value,
return true;
}
bool Reader::good() const { return !errors_.size(); }
bool Reader::good() const { return errors_.empty(); }
// exact copy of Features
class OurFeatures {
@@ -1895,7 +1895,7 @@ bool OurReader::pushError(const Value& value,
return true;
}
bool OurReader::good() const { return !errors_.size(); }
bool OurReader::good() const { return errors_.empty(); }
class OurCharReader : public CharReader {
bool const collectComments_;
@@ -1961,7 +1961,7 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const {
inv[key] = settings_[key];
}
}
return 0u == inv.size();
return inv.empty();
}
Value& CharReaderBuilder::operator[](const JSONCPP_STRING& key) {
return settings_[key];