Cleanup: Use is_empty() instead of size() == 0

This commit is contained in:
Hans Goudey
2023-12-11 13:54:57 -05:00
parent 4e10aa6e71
commit d8497e48e1
38 changed files with 52 additions and 52 deletions
@@ -656,7 +656,7 @@ inline TreeNode &Layer::as_node()
TREENODE_COMMON_METHODS_FORWARD_IMPL(Layer);
inline bool Layer::is_empty() const
{
return (this->frames().size() == 0);
return (this->frames().is_empty());
}
inline LayerGroup &Layer::parent_group() const
{
+1 -1
View File
@@ -200,7 +200,7 @@ struct NodeData {
{
undo_regions.clear();
for (UDIMTilePixels &tile : tiles) {
if (tile.pixel_rows.size() == 0) {
if (tile.pixel_rows.is_empty()) {
continue;
}
@@ -776,7 +776,7 @@ static GVArray adapt_mesh_attribute_domain(const Mesh &mesh,
if (!varray) {
return {};
}
if (varray.size() == 0) {
if (varray.is_empty()) {
return {};
}
if (from_domain == to_domain) {
@@ -771,7 +771,7 @@ FramesMapKey Layer::frame_key_at(const int frame_number) const
{
Span<int> sorted_keys = this->sorted_keys();
/* No keyframes, return no drawing. */
if (sorted_keys.size() == 0) {
if (sorted_keys.is_empty()) {
return -1;
}
/* Before the first drawing, return no drawing. */
@@ -1661,7 +1661,7 @@ static void remove_drawings_unchecked(GreasePencil &grease_pencil,
Span<int64_t> sorted_indices_to_remove)
{
using namespace blender::bke::greasepencil;
if (grease_pencil.drawing_array_num == 0 || sorted_indices_to_remove.size() == 0) {
if (grease_pencil.drawing_array_num == 0 || sorted_indices_to_remove.is_empty()) {
return;
}
const int64_t drawings_to_remove = sorted_indices_to_remove.size();
@@ -112,7 +112,7 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gpf,
/* Write point attributes. */
IndexRange stroke_points_range = points_by_curve[stroke_i];
if (stroke_points_range.size() == 0) {
if (stroke_points_range.is_empty()) {
continue;
}
@@ -817,7 +817,7 @@ Mesh *direct_mesh_boolean(Span<const Mesh *> meshes,
{
#ifdef WITH_GMP
BLI_assert(transforms.is_empty() || meshes.size() == transforms.size());
BLI_assert(material_remaps.size() == 0 || material_remaps.size() == meshes.size());
BLI_assert(material_remaps.is_empty() || material_remaps.size() == meshes.size());
if (meshes.size() <= 0) {
return nullptr;
}
@@ -506,7 +506,7 @@ static void face_edge_loop_islands_calc(const int totedge,
int tot_group = 0;
bool group_id_overflow = false;
if (faces.size() == 0) {
if (faces.is_empty()) {
*r_totgroup = 0;
*r_face_groups = nullptr;
if (r_edge_borders) {
@@ -318,7 +318,7 @@ void looptris_calc_with_normals(const Span<float3> vert_positions,
const Span<float3> face_normals,
MutableSpan<MLoopTri> looptris)
{
BLI_assert(!face_normals.is_empty() || faces.size() == 0);
BLI_assert(!face_normals.is_empty() || faces.is_empty());
looptris_calc_all(vert_positions, faces, corner_verts, face_normals, looptris);
}
+1 -1
View File
@@ -496,7 +496,7 @@ template<typename T> void cdt_draw(const std::string &label, const CDTArrangemen
constexpr bool draw_edge_labels = false;
constexpr bool draw_face_labels = false;
if (cdt.verts.size() == 0) {
if (cdt.verts.is_empty()) {
return;
}
vec2<double> vmin(DBL_MAX, DBL_MAX);
@@ -981,7 +981,7 @@ static Array<int> sort_tris_around_edge(
* be only 3 or 4 - so OK to make copies of arrays instead of swapping
* around in a single array. */
const int dbg_level = 0;
if (tris.size() == 0) {
if (tris.is_empty()) {
return Array<int>();
}
if (dbg_level > 0) {
@@ -1306,7 +1306,7 @@ static bool patch_cell_graph_ok(const CellsInfo &cinfo, const PatchesInfo &pinfo
if (cell.merged_to() != NO_INDEX) {
continue;
}
if (cell.patches().size() == 0) {
if (cell.patches().is_empty()) {
std::cout << "Patch/Cell graph disconnected at Cell " << c << " with no patches\n";
return false;
}
@@ -2132,7 +2132,7 @@ static void finish_patch_cell_graph(const IMesh &tm,
/* For nested components, merge their ambient cell with the nearest containing cell. */
Vector<int> outer_components;
for (int comp : comp_cont.index_range()) {
if (comp_cont[comp].size() == 0) {
if (comp_cont[comp].is_empty()) {
outer_components.append(comp);
}
else {
@@ -3217,7 +3217,7 @@ static void do_dissolve(FaceMergeState *fms)
dissolve_edges.append(e);
}
}
if (dissolve_edges.size() == 0) {
if (dissolve_edges.is_empty()) {
return;
}
/* Things look nicer if we dissolve the longer edges first. */
@@ -2126,7 +2126,7 @@ static Array<Face *> exact_triangulate_poly(Face *f, IMeshArena *arena)
bool needs_steiner = false;
for (int i = 0; i < 3; ++i) {
i_v_out[i] = cdt_out.face[t][i];
if (cdt_out.vert_orig[i_v_out[i]].size() == 0) {
if (cdt_out.vert_orig[i_v_out[i]].is_empty()) {
needs_steiner = true;
break;
}
@@ -2763,7 +2763,7 @@ static CoplanarClusterInfo find_clusters(const IMesh &tm,
if (dbg_level > 0) {
std::cout << "found " << maybe_coplanar_tris.size() << " possible coplanar tris\n";
}
if (maybe_coplanar_tris.size() == 0) {
if (maybe_coplanar_tris.is_empty()) {
if (dbg_level > 0) {
std::cout << "No possible coplanar tris, so no clusters\n";
}
@@ -2810,7 +2810,7 @@ static CoplanarClusterInfo find_clusters(const IMesh &tm,
no_int_cls.append(&cl);
}
}
if (int_cls.size() == 0) {
if (int_cls.is_empty()) {
/* t doesn't intersect any existing cluster in its plane, so make one just for it. */
if (dbg_level > 1) {
std::cout << "no intersecting clusters for t, make a new one\n";
@@ -284,7 +284,7 @@ void graph_draw(const std::string &label,
constexpr bool draw_vert_labels = false;
constexpr bool draw_edge_labels = false;
if (verts.size() == 0) {
if (verts.is_empty()) {
return;
}
vec2<double> vmin(1e10, 1e10);
@@ -119,7 +119,7 @@ Vector<MemoryBuffer *> ConstantFolder::get_constant_input_buffers(NodeOperation
Vector<ConstantOperation *> ConstantFolder::try_fold_operations(Span<NodeOperation *> operations)
{
Set<NodeOperation *> foldable_ops = find_constant_foldable_operations(operations);
if (foldable_ops.size() == 0) {
if (foldable_ops.is_empty()) {
return Vector<ConstantOperation *>();
}
@@ -194,7 +194,7 @@ const rcti &NodeOperation::get_canvas() const
void NodeOperation::unset_canvas()
{
BLI_assert(inputs_.size() == 0);
BLI_assert(inputs_.is_empty());
flags_.is_canvas_set = false;
}
@@ -217,7 +217,7 @@ bool NodeOperation::determine_depending_area_of_interest(rcti *input,
ReadBufferOperation *read_operation,
rcti *output)
{
if (inputs_.size() == 0) {
if (inputs_.is_empty()) {
BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
return false;
}
@@ -132,7 +132,7 @@ void MaskOperation::update_memory_buffer_partial(MemoryBuffer *output,
Span<MemoryBuffer *> /*inputs*/)
{
Vector<MaskRasterHandle *> handles = get_non_null_handles();
if (handles.size() == 0) {
if (handles.is_empty()) {
output->fill(area, COM_VALUE_ZERO);
return;
}
@@ -64,8 +64,8 @@ static void compute_marker_points(MovieClip *movie_clip,
Vector<float2> &marker_positions,
Vector<float4> &marker_colors)
{
BLI_assert(marker_positions.size() == 0);
BLI_assert(marker_colors.size() == 0);
BLI_assert(marker_positions.is_empty());
BLI_assert(marker_colors.is_empty());
ImBuf *image_buffer = BKE_movieclip_get_ibuf(movie_clip, &movie_clip_user);
if (!image_buffer) {
@@ -256,7 +256,7 @@ template<typename InstanceDataT> struct ShapeInstanceBuf : private select::Selec
void end_sync(PassSimple &pass, GPUBatch *shape)
{
if (data_buf.size() == 0) {
if (data_buf.is_empty()) {
return;
}
this->select_bind(pass);
@@ -616,7 +616,7 @@ static bke::CurvesGeometry remove_points_and_split(const bke::CurvesGeometry &cu
const Vector<IndexRange> ranges_to_keep = array_utils::find_all_ranges(curve_points_to_delete,
false);
if (ranges_to_keep.size() == 0) {
if (ranges_to_keep.is_empty()) {
continue;
}
@@ -1555,7 +1555,7 @@ static void duplicate_points(bke::CurvesGeometry &curves, const IndexMask &mask)
const Vector<IndexRange> ranges_to_duplicate = array_utils::find_all_ranges(
curve_points_to_duplicate, true);
if (ranges_to_duplicate.size() == 0) {
if (ranges_to_duplicate.is_empty()) {
continue;
}
@@ -199,7 +199,7 @@ static float *geodesic_mesh_create(Object *ob, GSet *initial_verts, const float
}
if (e_other != e && !BLI_BITMAP_TEST(edge_tag, e_other) &&
(ss->epmap[e_other].size() == 0 || dists[ev_other] != FLT_MAX))
(ss->epmap[e_other].is_empty() || dists[ev_other] != FLT_MAX))
{
if (BLI_BITMAP_TEST(affected_vertex, v_other) ||
BLI_BITMAP_TEST(affected_vertex, ev_other)) {
@@ -2769,7 +2769,7 @@ static void node_draw_extra_info_panel(const bContext &C,
preview = nullptr;
}
Vector<NodeExtraInfoRow> extra_info_rows = node_get_extra_info(C, tree_draw_ctx, snode, node);
if (extra_info_rows.size() == 0 && !preview) {
if (extra_info_rows.is_empty() && !preview) {
return;
}
@@ -452,7 +452,7 @@ static void connect_node_to_surface_output(const Span<bNodeTreePath *> treepath,
static void connect_nodes_to_aovs(const Span<bNodeTreePath *> treepath,
const Span<NodeSocketPair> &nodesocket_span)
{
if (nodesocket_span.size() == 0) {
if (nodesocket_span.is_empty()) {
return;
}
bNodeTree *main_nt = treepath.first()->nodetree;
@@ -242,7 +242,7 @@ static int retiming_key_add_to_editable_strips(bContext *C,
bool inserted = false;
blender::Map selection = SEQ_retiming_selection_get(ed);
if (selection.size() == 0) {
if (selection.is_empty()) {
return OPERATOR_CANCELLED;
}
@@ -87,7 +87,7 @@ static void createTransSeqRetimingData(bContext * /*C*/, TransInfo *t)
const blender::Map selection = SEQ_retiming_selection_get(SEQ_editing_get(t->scene));
if (selection.size() == 0) {
if (selection.is_empty()) {
return;
}
@@ -1223,7 +1223,7 @@ static void uvedit_pack_islands_multi(const Scene *scene,
}
}
if (island_vector.size() == 0) {
if (island_vector.is_empty()) {
return;
}
@@ -2882,7 +2882,7 @@ static int smart_project_exec(bContext *C, wmOperator *op)
project_angle_limit_cos,
area_weight);
if (project_normal_array.size() == 0) {
if (project_normal_array.is_empty()) {
MEM_freeN(thick_faces);
continue;
}
@@ -384,7 +384,7 @@ static void weld_edge_find_doubles(Span<WeldEdge> weld_edges,
/* Setup Edge Overlap. */
int edge_double_kill_len = 0;
if (weld_edges.size() == 0) {
if (weld_edges.is_empty()) {
*r_edge_double_kill_len = edge_double_kill_len;
return;
}
@@ -1041,7 +1041,7 @@ static int poly_find_doubles(const OffsetIndices<int> poly_corners_offsets,
/* Use a reverse for loop to ensure that indexes are assigned in ascending order. */
for (int face_index = poly_num; face_index--;) {
if (poly_corners_offsets[face_index].size() == 0) {
if (poly_corners_offsets[face_index].is_empty()) {
continue;
}
+2 -2
View File
@@ -1493,7 +1493,7 @@ static bool rotate_inside_square(const Span<std::unique_ptr<UVAABBIsland>> islan
MutableSpan<UVPhi> r_phis,
rctf *r_extent)
{
if (island_indices.size() == 0) {
if (island_indices.is_empty()) {
return false; /* Nothing to do. */
}
if (params.rotate_method != ED_UVPACK_ROTATION_ANY) {
@@ -2250,7 +2250,7 @@ float pack_islands(const Span<PackIsland *> &islands, const UVPackIsland_Params
BLI_assert(0.0f <= params.margin);
BLI_assert(0.0f <= params.target_aspect_y);
if (islands.size() == 0) {
if (islands.is_empty()) {
return 1.0f; /* Nothing to do, just create a safe default. */
}
+1 -1
View File
@@ -47,7 +47,7 @@ void GPU_debug_get_groups_names(int name_buf_len, char *r_name_buf)
return;
}
DebugStack &stack = ctx->debug_stack;
if (stack.size() == 0) {
if (stack.is_empty()) {
r_name_buf[0] = '\0';
return;
}
+1 -1
View File
@@ -64,7 +64,7 @@ Shader::~Shader()
static void standard_defines(Vector<const char *> &sources)
{
BLI_assert(sources.size() == 0);
BLI_assert(sources.is_empty());
/* Version needs to be first. Exact values will be added by implementation. */
sources.append("version");
/* Define to identify code usage in shading language. */
@@ -575,7 +575,7 @@ struct GPUSource {
CHECK(char_end, input, cursor, "Malformed char literal. Missing ending `'`.");
StringRef input_char = input.substr(char_start, char_end - char_start);
if (input_char.size() == 0) {
if (input_char.is_empty()) {
CHECK(-1, input, cursor, "Malformed char literal. Empty character constant");
}
@@ -29,7 +29,7 @@ ShaderInterface::~ShaderInterface()
static void sort_input_list(MutableSpan<ShaderInput> dst)
{
if (dst.size() == 0) {
if (dst.is_empty()) {
return;
}
+1 -1
View File
@@ -77,7 +77,7 @@ void Shader::print_log(Span<const char *> sources,
}
#endif
}
if (sources_end_line.size() == 0) {
if (sources_end_line.is_empty()) {
sources_end_line.append(0);
}
@@ -65,7 +65,7 @@ static void initialize_posetree(Object * /*ob*/, bPoseChannel *pchan_tip)
blender::Vector<bConstraint *> ik_constraints;
find_ik_constraints(&pchan_tip->constraints, ik_constraints);
if (ik_constraints.size() == 0) {
if (ik_constraints.is_empty()) {
return;
}
@@ -669,7 +669,7 @@ void MTLWriter::write_materials(const char *blen_filepath,
const char *dest_dir,
bool write_pbr)
{
if (mtlmaterials_.size() == 0) {
if (mtlmaterials_.is_empty()) {
return;
}
+2 -2
View File
@@ -539,7 +539,7 @@ static void end_node_frames(int v,
const float *rad = nodes[v].radius;
float mat[3][3];
if (emap[v].size() == 0) {
if (emap[v].is_empty()) {
float avg = half_v2(rad);
/* For solitary nodes, just build a box (two frames) */
@@ -814,7 +814,7 @@ static EMat *build_edge_mats(const MVertSkin *vs,
*has_valid_root = true;
}
else if (edges.size() == 0) {
else if (edges.is_empty()) {
/* Vertex-only mesh is valid, mark valid root as well (will display error otherwise). */
*has_valid_root = true;
break;
@@ -332,7 +332,7 @@ static bool sort_vertex_faces(const Span<int2> edges,
MutableSpan<int> r_shared_edges,
MutableSpan<int> r_sorted_corners)
{
if (connected_faces.size() <= 2 && (!boundary_vertex || connected_faces.size() == 0)) {
if (connected_faces.size() <= 2 && (!boundary_vertex || connected_faces.is_empty())) {
return true;
}
@@ -408,7 +408,7 @@ static void copy_stable_id_faces(const Mesh &mesh,
int loop_index = 0;
for (const int i_face : selection.index_range()) {
const IndexRange range = face_offsets[i_face];
if (range.size() == 0) {
if (range.is_empty()) {
continue;
}
const IndexRange source = faces[i_face];
@@ -950,7 +950,7 @@ static void duplicate_instances(GeometrySet &geometry_set,
dst_instances->resize(duplicates.total_size());
for (const int i_selection : selection.index_range()) {
const IndexRange range = duplicates[i_selection];
if (range.size() == 0) {
if (range.is_empty()) {
continue;
}
const int old_handle = src_instances.reference_handles()[i_selection];
@@ -33,7 +33,7 @@ static void node_geo_exec(GeoNodeExecParams params)
evaluator.add(params.get_input<Field<bool>>("Selection"));
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_as_mask(0);
if (selection.size() == 0) {
if (selection.is_empty()) {
geometry_set.remove_geometry_during_modify();
return;
}
@@ -373,7 +373,7 @@ static void node_geo_exec(GeoNodeExecParams params)
params.set_output("Remainder", std::move(layout->truncated_text));
}
if (layout->positions.size() == 0) {
if (layout->positions.is_empty()) {
params.set_output("Curve Instances", GeometrySet());
params.set_default_remaining_outputs();
return;