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

@@ -551,7 +551,7 @@ bool StyledWriter::isMultilineArray(const Value& value) {
for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
const Value& childValue = value[index];
isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
childValue.size() > 0);
!childValue.empty());
}
if (!isMultiLine) // check if line length > max line length
{
@@ -774,7 +774,7 @@ bool StyledStreamWriter::isMultilineArray(const Value& value) {
for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
const Value& childValue = value[index];
isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
childValue.size() > 0);
!childValue.empty());
}
if (!isMultiLine) // check if line length > max line length
{
@@ -1059,7 +1059,7 @@ bool BuiltStyledStreamWriter::isMultilineArray(Value const& value) {
for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
Value const& childValue = value[index];
isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
childValue.size() > 0);
!childValue.empty());
}
if (!isMultiLine) // check if line length > max line length
{
@@ -1226,7 +1226,7 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const {
inv[key] = settings_[key];
}
}
return 0u == inv.size();
return inv.empty();
}
Value& StreamWriterBuilder::operator[](const JSONCPP_STRING& key) {
return settings_[key];