Clang-tidy: enable readability-container-size-empty warning

Reviewers: sergey

Differential Revision: https://developer.blender.org/D8197
This commit is contained in:
Jacques Lucke 2020-07-03 14:59:27 +02:00
parent 93da09d717
commit 2633683b52
23 changed files with 67 additions and 67 deletions

View File

@ -25,7 +25,6 @@ Checks: >
-readability-redundant-string-init,
-readability-redundant-member-init,
-readability-const-return-type,
-readability-container-size-empty,
-readability-redundant-string-cstr,
-readability-static-accessed-through-instance,
-readability-redundant-declaration,

View File

@ -152,7 +152,7 @@ static struct VolumeFileCache {
~VolumeFileCache()
{
assert(cache.size() == 0);
assert(cache.empty());
}
Entry *add_metadata_user(const Entry &template_entry)

View File

@ -184,7 +184,7 @@ bool WorkScheduler::hasGPUDevices()
{
#if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE
# ifdef COM_OPENCL_ENABLED
return g_gpudevices.size() > 0;
return !g_gpudevices.empty();
# else
return 0;
# endif
@ -210,7 +210,7 @@ void WorkScheduler::initialize(bool use_opencl, int num_cpu_threads)
if (g_cpudevices.size() != num_cpu_threads) {
Device *device;
while (g_cpudevices.size() > 0) {
while (!g_cpudevices.empty()) {
device = g_cpudevices.back();
g_cpudevices.pop_back();
device->deinitialize();
@ -331,7 +331,7 @@ void WorkScheduler::deinitialize()
/* deinitialize CPU threads */
if (g_cpuInitialized) {
Device *device;
while (g_cpudevices.size() > 0) {
while (!g_cpudevices.empty()) {
device = g_cpudevices.back();
g_cpudevices.pop_back();
device->deinitialize();
@ -345,7 +345,7 @@ void WorkScheduler::deinitialize()
/* deinitialize OpenCL GPU's */
if (g_openclInitialized) {
Device *device;
while (g_gpudevices.size() > 0) {
while (!g_gpudevices.empty()) {
device = g_gpudevices.back();
g_gpudevices.pop_back();
device->deinitialize();

View File

@ -469,7 +469,7 @@ void Controller::DeleteViewMap(bool freeCache)
void Controller::ComputeViewMap()
{
if (!_ListOfModels.size()) {
if (_ListOfModels.empty()) {
return;
}

View File

@ -746,7 +746,7 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
detriList.push_back(detri);
}
if (detriList.size() > 0) {
if (!detriList.empty()) {
vector<detri_t>::iterator v;
for (v = detriList.begin(); v != detriList.end(); v++) {
detri_t detri = (*v);

View File

@ -93,7 +93,7 @@ bool firstIntersectionGridVisitor::stop()
/////////////////
void Grid::clear()
{
if (_occluders.size() != 0) {
if (!_occluders.empty()) {
for (OccludersSet::iterator it = _occluders.begin(); it != _occluders.end(); it++) {
delete (*it);
}
@ -154,7 +154,7 @@ void Grid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb)
void Grid::insertOccluder(Polygon3r *occluder)
{
const vector<Vec3r> vertices = occluder->getVertices();
if (vertices.size() == 0) {
if (vertices.empty()) {
return;
}

View File

@ -27,7 +27,7 @@ NodeShape::~NodeShape()
{
vector<Rep *>::iterator rep;
if (0 != _Shapes.size()) {
if (!_Shapes.empty()) {
for (rep = _Shapes.begin(); rep != _Shapes.end(); ++rep) {
int refCount = (*rep)->destroy();
if (0 == refCount) {

View File

@ -633,7 +633,7 @@ static void computeCumulativeVisibility(ViewMap *ioViewMap,
wFaces.clear();
}
if (iRenderMonitor && vedges.size()) {
if (iRenderMonitor && !vedges.empty()) {
stringstream ss;
ss << "Freestyle: Visibility computations " << (100 * cnt / vedges.size()) << "%";
iRenderMonitor->setInfo(ss.str());

View File

@ -25,7 +25,7 @@ namespace Freestyle {
NodeGroup *ViewMapTesselator::Tesselate(ViewMap *iViewMap)
{
if (0 == iViewMap->ViewEdges().size()) {
if (iViewMap->ViewEdges().empty()) {
return NULL;
}

View File

@ -200,7 +200,7 @@ bool WingedEdgeBuilder::buildWShape(WShape &shape, IndexedFaceSet &ifs)
delete[] new_vertices;
delete[] new_normals;
if (shape.GetFaceList().size() == 0) { // this may happen due to degenerate triangles
if (shape.GetFaceList().empty()) { // this may happen due to degenerate triangles
return false;
}
@ -219,8 +219,8 @@ bool WingedEdgeBuilder::buildWShape(WShape &shape, IndexedFaceSet &ifs)
if ((*wv)->isBoundary()) {
continue;
}
if ((*wv)->GetEdges().size() ==
0) { // This means that the WVertex has no incoming edges... (12-Sep-2011 T.K.)
if ((*wv)->GetEdges().empty()) {
// This means that the WVertex has no incoming edges... (12-Sep-2011 T.K.)
continue;
}
normalsSet.clear();

View File

@ -816,7 +816,7 @@ void IMB_exr_add_channel(void *handle,
if (layname && layname[0] != '\0') {
imb_exr_insert_view_name(echan->name, echan->m->name.c_str(), echan->m->view.c_str());
}
else if (data->multiView->size() >= 1) {
else if (!data->multiView->empty()) {
std::string raw_name = insertViewName(echan->m->name, *data->multiView, echan->view_id);
BLI_strncpy(echan->name, raw_name.c_str(), sizeof(echan->name));
}
@ -1066,7 +1066,7 @@ float *IMB_exr_channel_rect(void *handle,
imb_exr_insert_view_name(temp_buf, name, viewname);
BLI_strncpy(name, temp_buf, sizeof(name));
}
else if (data->multiView->size() >= 1) {
else if (!data->multiView->empty()) {
const int view_id = std::max(0, imb_exr_get_multiView_id(*data->multiView, viewname));
std::string raw_name = insertViewName(name, *data->multiView, view_id);
BLI_strncpy(name, raw_name.c_str(), sizeof(name));
@ -1300,7 +1300,7 @@ void IMB_exr_multilayer_convert(void *handle,
ExrPass *pass;
/* RenderResult needs at least one RenderView */
if (data->multiView->size() == 0) {
if (data->multiView->empty()) {
addview(base, "");
}
else {
@ -1775,7 +1775,7 @@ static bool imb_exr_is_multilayer_file(MultiPartInputFile &file)
* channels without a layer name will be single layer. */
channels.layers(layerNames);
return (layerNames.size() > 0);
return (!layerNames.empty());
}
static void imb_exr_type_by_channels(ChannelList &channels,
@ -1792,7 +1792,7 @@ static void imb_exr_type_by_channels(ChannelList &channels,
/* will not include empty layer names */
channels.layers(layerNames);
if (views.size() && views[0] != "") {
if (!views.empty() && !views[0].empty()) {
*r_multiview = true;
}
else {
@ -1802,7 +1802,7 @@ static void imb_exr_type_by_channels(ChannelList &channels,
return;
}
if (layerNames.size()) {
if (!layerNames.empty()) {
/* if layerNames is not empty, it means at least one layer is non-empty,
* but it also could be layers without names in the file and such case
* shall be considered a multilayer exr

View File

@ -282,10 +282,10 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context,
norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[2], -tmpnor[1]));
}
else {
if (uv_values.size()) {
if (!uv_values.empty()) {
uv_values.push_back(uv_values[pc->parent]);
}
if (norm_values.size()) {
if (!norm_values.empty()) {
norm_values.push_back(norm_values[pc->parent]);
}
}

View File

@ -443,7 +443,7 @@ void ABCGenericMeshWriter::get_geo_groups(Object *object,
geo_groups[name].push_back(i);
}
if (geo_groups.size() == 0) {
if (geo_groups.empty()) {
Material *mat = BKE_object_material_get(object, 1);
std::string name = (mat) ? args_.hierarchy_iterator->get_id_name(&mat->id) : "default";

View File

@ -373,7 +373,7 @@ static std::pair<bool, AbcObjectReader *> visit_object(
}
}
else if (object.getParent()) {
if (claiming_child_readers.size() > 0) {
if (!claiming_child_readers.empty()) {
/* The first claiming child will serve just fine as parent to
* our non-claiming children. Since all claiming children share
* the same XForm, it doesn't really matter which one we pick. */
@ -479,7 +479,7 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
visit_object(archive->getTop(), data->readers, data->settings, assign_as_parent);
/* There shouldn't be any orphans. */
BLI_assert(assign_as_parent.size() == 0);
BLI_assert(assign_as_parent.empty());
if (G.is_break) {
data->was_cancelled = true;

View File

@ -222,7 +222,7 @@ void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &
std::vector<float> frames;
sampler.get_object_frames(frames, ob);
if (frames.size() > 0) {
if (!frames.empty()) {
BCMatrixSampleMap samples;
bool is_animated = sampler.get_object_samples(samples, ob);
if (keep_flat_curves || is_animated) {
@ -264,7 +264,7 @@ void AnimationExporter::export_bone_animations_recursive(Object *ob,
std::vector<float> frames;
sampler.get_bone_frames(frames, ob, bone);
if (frames.size()) {
if (!frames.empty()) {
BCMatrixSampleMap samples;
bool is_animated = sampler.get_bone_samples(samples, ob, bone);
if (keep_flat_curves || is_animated) {
@ -542,7 +542,7 @@ void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNa
param.push_back("ANGLE");
}
else {
if (axis != "") {
if (!axis.empty()) {
param.push_back(axis);
}
else if (transform) {
@ -836,11 +836,11 @@ std::string AnimationExporter::get_collada_sid(const BCAnimationCurve &curve,
bool is_angle = curve.is_rotation_curve();
if (tm_name.size()) {
if (!tm_name.empty()) {
if (is_angle) {
return tm_name + std::string(axis_name) + ".ANGLE";
}
else if (axis_name != "") {
else if (!axis_name.empty()) {
return tm_name + "." + std::string(axis_name);
}
else {

View File

@ -52,7 +52,7 @@
template<class T> static const char *bc_get_joint_name(T *node)
{
const std::string &id = node->getName();
return id.size() ? id.c_str() : node->getOriginalId().c_str();
return id.empty() ? node->getOriginalId().c_str() : id.c_str();
}
FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path)
@ -277,7 +277,7 @@ AnimationImporter::~AnimationImporter()
BKE_fcurve_free(*it);
}
if (unused_curves.size()) {
if (!unused_curves.empty()) {
fprintf(stderr, "removed %d unused curves\n", (int)unused_curves.size());
}
}
@ -738,7 +738,7 @@ void AnimationImporter::Assign_float_animations(const COLLADAFW::UniqueId &listi
/* NOTE: Do NOT convert if imported file was made by blender <= 2.69.10
* Reason: old blender versions stored spot_size in radians (was a bug)
*/
if (this->import_from_version == "" ||
if (this->import_from_version.empty() ||
BLI_strcasecmp_natural(this->import_from_version.c_str(), "2.69.10") != -1) {
fcurve_deg_to_rad(fcu);
}
@ -878,7 +878,7 @@ void AnimationImporter::apply_matrix_curves(Object *ob,
newcu[i]->totvert = frames.size();
}
if (frames.size() == 0) {
if (frames.empty()) {
return;
}
@ -1333,7 +1333,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob,
newcu[i]->totvert = frames.size();
}
if (frames.size() == 0) {
if (frames.empty()) {
return;
}
@ -1641,7 +1641,7 @@ Object *AnimationImporter::translate_animation_OLD(
job = get_joint_object(root, node, par_job);
#endif
if (frames.size() == 0) {
if (frames.empty()) {
return job;
}
@ -1876,7 +1876,7 @@ void AnimationImporter::evaluate_transform_at_frame(float mat[4][4],
unit_m4(m);
std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName();
if (!evaluate_animation(tm, m, fra, nodename.c_str())) {
switch (type) {
case COLLADAFW::Transformation::ROTATE:

View File

@ -41,7 +41,7 @@
template<class T> static const char *bc_get_joint_name(T *node)
{
const std::string &id = node->getName();
return id.size() ? id.c_str() : node->getOriginalId().c_str();
return id.empty() ? node->getOriginalId().c_str() : id.c_str();
}
ArmatureImporter::ArmatureImporter(UnitConverter *conv,
@ -606,7 +606,7 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo &skin)
}
}
if (!shared && this->joint_parent_map.size() > 0) {
if (!shared && !this->joint_parent_map.empty()) {
/* All armatures have been created while creating the Node tree.
* The Collada exporter currently does not create a
* strict relationship between geometries and armatures

View File

@ -78,7 +78,7 @@ void BCAnimationSampler::add_object(Object *ob)
BCAnimationCurveMap *BCAnimationSampler::get_curves(Object *ob)
{
BCAnimation &animation = *objects[ob];
if (animation.curve_map.size() == 0) {
if (animation.curve_map.empty()) {
initialize_curves(animation.curve_map, ob);
}
return &animation.curve_map;
@ -279,7 +279,7 @@ void BCAnimationSampler::find_depending_animated(std::set<Object *> &animated_ob
break;
}
}
} while (found_more && candidates.size() > 0);
} while (found_more && !candidates.empty());
}
void BCAnimationSampler::get_animated_from_export_set(std::set<Object *> &animated_objects,

View File

@ -251,7 +251,7 @@ void DocumentImporter::finish()
}
}
if (libnode_ob.size()) {
if (!libnode_ob.empty()) {
fprintf(stderr, "| Cleanup: free %d library nodes\n", (int)libnode_ob.size());
/* free all library_nodes */
@ -667,7 +667,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node,
for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end();
++it) {
ob = *it;
std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName();
BKE_libblock_rename(bmain, &ob->id, (char *)nodename.c_str());
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob));
node_map[node->getUniqueId()] = node;
@ -699,11 +699,11 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node,
}
}
if (objects_done->size() > 0) {
ob = *objects_done->begin();
if (objects_done->empty()) {
ob = NULL;
}
else {
ob = NULL;
ob = *objects_done->begin();
}
for (unsigned int i = 0; i < child_nodes.getCount(); i++) {
@ -792,7 +792,8 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat)
}
Main *bmain = CTX_data_main(mContext);
const std::string &str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId();
const std::string &str_mat_id = cmat->getName().empty() ? cmat->getOriginalId() :
cmat->getName();
Material *ma = BKE_material_add(bmain, (char *)str_mat_id.c_str());
this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;
@ -880,11 +881,11 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera)
ExtraTags *et = getExtraTags(camera->getUniqueId());
cam_id = camera->getOriginalId();
cam_name = camera->getName();
if (cam_name.size()) {
cam = (Camera *)BKE_camera_add(bmain, (char *)cam_name.c_str());
if (cam_name.empty()) {
cam = (Camera *)BKE_camera_add(bmain, (char *)cam_id.c_str());
}
else {
cam = (Camera *)BKE_camera_add(bmain, (char *)cam_id.c_str());
cam = (Camera *)BKE_camera_add(bmain, (char *)cam_name.c_str());
}
if (!cam) {
@ -1042,11 +1043,11 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
la_id = light->getOriginalId();
la_name = light->getName();
if (la_name.size()) {
lamp = (Light *)BKE_light_add(bmain, (char *)la_name.c_str());
if (la_name.empty()) {
lamp = (Light *)BKE_light_add(bmain, (char *)la_id.c_str());
}
else {
lamp = (Light *)BKE_light_add(bmain, (char *)la_id.c_str());
lamp = (Light *)BKE_light_add(bmain, (char *)la_name.c_str());
}
if (!lamp) {

View File

@ -50,7 +50,7 @@
// get node name, or fall back to original id if not present (name is optional)
template<class T> static const std::string bc_get_dae_name(T *node)
{
return node->getName().size() ? node->getName() : node->getOriginalId();
return node->getName().empty() ? node->getOriginalId() : node->getName();
}
static const char *bc_primTypeToStr(COLLADAFW::MeshPrimitive::PrimitiveType type)
@ -1126,7 +1126,7 @@ Object *MeshImporter::create_mesh_object(
}
// name Object
const std::string &id = node->getName().size() ? node->getName() : node->getOriginalId();
const std::string &id = node->getName().empty() ? node->getOriginalId() : node->getName();
const char *name = (id.length()) ? id.c_str() : NULL;
// add object
@ -1185,8 +1185,8 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom)
return true;
}
const std::string &str_geom_id = mesh->getName().size() ? mesh->getName() :
mesh->getOriginalId();
const std::string &str_geom_id = mesh->getName().empty() ? mesh->getOriginalId() :
mesh->getName();
Mesh *me = BKE_mesh_add(m_bmain, (char *)str_geom_id.c_str());
id_us_min(&me->id); // is already 1 here, but will be set later in BKE_mesh_assign_object

View File

@ -49,7 +49,7 @@
template<class T> static const char *bc_get_joint_name(T *node)
{
const std::string &id = node->getName();
return id.size() ? id.c_str() : node->getOriginalId().c_str();
return id.empty() ? node->getOriginalId().c_str() : id.c_str();
}
/* This is used to store data passed in write_controller_data.

View File

@ -221,7 +221,7 @@ std::string translate_id(const char *idString)
std::string translate_id(const std::string &id)
{
if (id.size() == 0) {
if (id.empty()) {
return id;
}

View File

@ -219,18 +219,18 @@ void AbstractHierarchyIterator::debug_print_export_graph(const ExportGraph &grap
printf(" - %s%s%s\n",
child_ctx->object->id.name + 2,
child_ctx->weak_export ? " (weak)" : "",
child_ctx->original_export_path.size() ?
(std::string("ref ") + child_ctx->original_export_path).c_str() :
"");
child_ctx->original_export_path.empty() ?
"" :
(std::string("ref ") + child_ctx->original_export_path).c_str());
}
else {
printf(" - %s (dup by %s%s) %s\n",
child_ctx->object->id.name + 2,
child_ctx->duplicator->id.name + 2,
child_ctx->weak_export ? ", weak" : "",
child_ctx->original_export_path.size() ?
(std::string("ref ") + child_ctx->original_export_path).c_str() :
"");
child_ctx->original_export_path.empty() ?
"" :
(std::string("ref ") + child_ctx->original_export_path).c_str());
}
}
}