Cleanup: use BLI_listbase_count_ex to avoid redundant looping

This commit is contained in:
Campbell Barton 2014-11-16 14:23:37 +01:00
parent 0e60accf2a
commit c31f74de6b
Notes: blender-bot 2023-02-14 06:49:57 +01:00
Referenced by commit f11bcbed9d, Fix T51913: Context tab for textures issue
13 changed files with 24 additions and 19 deletions

View File

@ -1098,7 +1098,7 @@ bool BKE_object_lod_remove(Object *ob, int level)
MEM_freeN(rem);
/* If there are no user defined lods, remove the base lod as well */
if (BLI_listbase_count(&ob->lodlevels) == 1) {
if (BLI_listbase_is_single(&ob->lodlevels)) {
LodLevel *base = ob->lodlevels.first;
BLI_remlink(&ob->lodlevels, base);
MEM_freeN(base);

View File

@ -3513,7 +3513,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
psys->part = psys_new_settings(DATA_("ParticleSettings"), NULL);
if (BLI_listbase_count(&ob->particlesystem) > 1)
if (BLI_listbase_count_ex(&ob->particlesystem, 2) > 1)
BLI_snprintf(psys->name, sizeof(psys->name), DATA_("ParticleSystem %i"), BLI_listbase_count(&ob->particlesystem));
else
BLI_strncpy(psys->name, DATA_("ParticleSystem"), sizeof(psys->name));

View File

@ -3561,7 +3561,7 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob)
if (ob->softflag & OB_SB_EDGES) {
if (ob->type==OB_CURVE) {
totspring= totvert - BLI_listbase_count(&cu->nurb);
totspring = totvert - BLI_listbase_count(&cu->nurb);
}
}

View File

@ -372,6 +372,11 @@ void BLI_freelistN(ListBase *listbase)
BLI_listbase_clear(listbase);
}
/**
* Returns the number of elements in \a listbase, up until (and including count_max)
*
* \note Use to avoid redundant looping.
*/
int BLI_listbase_count_ex(const ListBase *listbase, const int count_max)
{
Link *link;

View File

@ -656,7 +656,7 @@ static bool bm_uuidwalk_facestep_begin(
bool ok = false;
BLI_assert(BLI_ghash_size(uuidwalk->cache.faces_from_uuid) == 0);
BLI_assert(BLI_listbase_count(&fstep->items) == 0);
BLI_assert(BLI_listbase_is_empty(&fstep->items));
f_link_prev_p = &fstep->faces;
for (f_link = fstep->faces; f_link; f_link = f_link_next) {

View File

@ -168,7 +168,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce,
node.setNodeSid(node_sid);
#if 0
if (BLI_listbase_is_empty(&bone->childbase) || BLI_listbase_count(&(bone->childbase)) >= 2) {
if (BLI_listbase_is_empty(&bone->childbase) || BLI_listbase_count_ex(&bone->childbase, 2) == 2) {
add_blender_leaf_bone( bone, ob_arm, node);
}
else {

View File

@ -1205,7 +1205,7 @@ static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bo
static void RIG_findHead(RigGraph *rg)
{
if (rg->head == NULL) {
if (BLI_listbase_count(&rg->arcs) == 1) {
if (BLI_listbase_is_single(&rg->arcs)) {
RigArc *arc = rg->arcs.first;
rg->head = (RigNode *)arc->head;
@ -2152,7 +2152,7 @@ void exec_retargetArctoArc(TaskPool *UNUSED(pool), void *taskdata, int UNUSED(th
RigNode *inode_start = p->inode_start;
ReebArc *earc = iarc->link_mesh;
if (BLI_listbase_count(&iarc->edges) == 1) {
if (BLI_listbase_is_single(&iarc->edges)) {
RigEdge *edge = iarc->edges.first;
if (testFlipArc(iarc, inode_start)) {

View File

@ -2460,7 +2460,7 @@ void renormalizeWeight(EditMesh *em, float newmax)
EditVert *eve;
float minimum, maximum, range;
if (em == NULL || BLI_listbase_count(&em->verts) == 0)
if (em == NULL || BLI_listbase_is_empty(&em->verts))
return;
/* First pass, determine maximum and minimum */
@ -2486,7 +2486,7 @@ int weightFromLoc(EditMesh *em, int axis)
{
EditVert *eve;
if (em == NULL || BLI_listbase_count(&em->verts) == 0 || axis < 0 || axis > 2)
if (em == NULL || BLI_listbase_is_empty(&em->verts) || axis < 0 || axis > 2)
return 0;
/* Copy coordinate in weight */

View File

@ -749,12 +749,8 @@ static void knife_cut_face(KnifeTool_OpData *kcd, BMFace *f, ListBase *hits)
{
Ref *r;
KnifeLineHit *lh, *prevlh;
int n;
(void) kcd;
n = BLI_listbase_count(hits);
if (n < 2)
if (BLI_listbase_count_ex(hits, 2) != 2)
return;
prevlh = NULL;
@ -2108,7 +2104,7 @@ static ListBase *find_chain(KnifeTool_OpData *kcd, ListBase *fedges)
break;
}
if (ans) {
BLI_assert(BLI_listbase_count(ans) > 0);
BLI_assert(!BLI_listbase_is_empty(ans));
for (r = ans->first; r; r = r->next) {
ref = find_ref(fedges, r->ref);
BLI_assert(ref != NULL);

View File

@ -468,7 +468,7 @@ void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
}
else {
/* set one user as active based on active index */
if (ct->index >= BLI_listbase_count(&ct->users))
if (ct->index == BLI_listbase_count_ex(&ct->users, ct->index))
ct->index = 0;
ct->user = BLI_findlink(&ct->users, ct->index);

View File

@ -1436,7 +1436,9 @@ static int nlaedit_swap_exec(bContext *C, wmOperator *op)
if (BLI_listbase_is_empty(&nlt->strips) == false) {
NlaStrip *mstrip = (NlaStrip *)nlt->strips.first;
if ((mstrip->flag & NLASTRIP_FLAG_TEMP_META) && (BLI_listbase_count(&mstrip->strips) == 2)) {
if ((mstrip->flag & NLASTRIP_FLAG_TEMP_META) &&
(BLI_listbase_count_ex(&mstrip->strips, 3) == 2))
{
/* remove this temp meta, so that we can see the strips inside */
BKE_nlastrips_clear_metas(&nlt->strips, 0, 1);
}

View File

@ -1568,7 +1568,7 @@ static KX_GameObject *gameobject_from_blenderobject(
gameobj->AddMesh(meshobj);
// gather levels of detail
if (BLI_listbase_count(&ob->lodlevels) > 1) {
if (BLI_listbase_count_ex(&ob->lodlevels, 2) > 1) {
LodLevel *lod = ((LodLevel*)ob->lodlevels.first)->next;
Mesh* lodmesh = mesh;
Object* lodmatob = ob;

View File

@ -200,12 +200,14 @@ void BL_SkinDeformer::BGEDeformVerts()
Object *par_arma = m_armobj->GetArmatureObject();
MDeformVert *dverts = m_bmesh->dvert;
bDeformGroup *dg;
int defbase_tot = BLI_listbase_count(&m_objMesh->defbase);
int defbase_tot;
Eigen::Matrix4f pre_mat, post_mat, chan_mat, norm_chan_mat;
if (!dverts)
return;
defbase_tot = BLI_listbase_count(&m_objMesh->defbase);
if (m_dfnrToPC == NULL)
{
m_dfnrToPC = new bPoseChannel*[defbase_tot];