code cleanup: use min/max inline functions rather than macros & simplify loop
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2012 09:39:37 +0000 (09:39 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2012 09:39:37 +0000 (09:39 +0000)
source/blender/blenkernel/intern/fcurve.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/object.c
source/blender/bmesh/intern/bmesh_iterators.c
source/blender/makesrna/intern/rna_access.c

index 5fea74d52debee926fac09c0e248214363536a95..2dbc63e6944973372aed44821f4633f647cf25ba 100644 (file)
@@ -504,8 +504,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo
                                                xmaxv = MAX3(xmaxv, bezt_last->vec[1][0],  bezt_last->vec[2][0]);
                                        }
                                        else {
-                                               xminv = MIN2(xminv, bezt_first->vec[1][0]);
-                                               xmaxv = MAX2(xmaxv, bezt_last->vec[1][0]);
+                                               xminv = minf(xminv, bezt_first->vec[1][0]);
+                                               xmaxv = maxf(xmaxv, bezt_last->vec[1][0]);
                                        }
                                }
                        }
@@ -521,8 +521,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo
                                                        ymaxv = MAX4(ymaxv, bezt->vec[1][1], bezt->vec[0][1], bezt->vec[2][1]);
                                                }
                                                else {
-                                                       yminv = MIN2(yminv, bezt->vec[1][1]);
-                                                       ymaxv = MAX2(ymaxv, bezt->vec[1][1]);
+                                                       yminv = minf(yminv, bezt->vec[1][1]);
+                                                       ymaxv = maxf(ymaxv, bezt->vec[1][1]);
                                                }
                                                
                                                foundvert = TRUE;
@@ -533,8 +533,8 @@ short calc_fcurve_bounds(FCurve *fcu, float *xmin, float *xmax, float *ymin, flo
                else if (fcu->fpt) {
                        /* frame range can be directly calculated from end verts */
                        if (xmin || xmax) {
-                               xminv = MIN2(xminv, fcu->fpt[0].vec[0]);
-                               xmaxv = MAX2(xmaxv, fcu->fpt[fcu->totvert - 1].vec[0]);
+                               xminv = minf(xminv, fcu->fpt[0].vec[0]);
+                               xmaxv = maxf(xmaxv, fcu->fpt[fcu->totvert - 1].vec[0]);
                        }
                        
                        /* only loop over keyframes to find extents for values if needed */
@@ -591,15 +591,15 @@ void calc_fcurve_range(FCurve *fcu, float *start, float *end,
                        if (bezt_first) {
                                BLI_assert(bezt_last != NULL);
                                
-                               min = MIN2(min, bezt_first->vec[1][0]);
-                               max = MAX2(max, bezt_last->vec[1][0]);
+                               min = minf(min, bezt_first->vec[1][0]);
+                               max = maxf(max, bezt_last->vec[1][0]);
                                
                                foundvert = TRUE;
                        }
                }
                else if (fcu->fpt) {
-                       min = MIN2(min, fcu->fpt[0].vec[0]);
-                       max = MAX2(max, fcu->fpt[fcu->totvert - 1].vec[0]);
+                       min = minf(min, fcu->fpt[0].vec[0]);
+                       max = maxf(max, fcu->fpt[fcu->totvert - 1].vec[0]);
                        
                        foundvert = TRUE;
                }
index 17a3c595ea72fbb7b10f59d6edf01d2aebbe7c35..b79608342dd565f9ceaaa4e168a3e8eb15917f07 100644 (file)
@@ -691,8 +691,8 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const
                if (nu->bp) {
                        step = nu->pntsu * nu->pntsv;
 
-                       a1 = MAX2(a, start);
-                       a2 = MIN2(a + step, end);
+                       a1 = maxi(a, start);
+                       a2 = mini(a + step, end);
 
                        if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT);
                }
@@ -700,8 +700,8 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const
                        step = 3 * nu->pntsu;
 
                        /* exception because keys prefer to work with complete blocks */
-                       a1 = MAX2(a, start);
-                       a2 = MIN2(a + step, end);
+                       a1 = maxi(a, start);
+                       a2 = mini(a + step, end);
 
                        if (a1 < a2) cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BEZTRIPLE);
                }
@@ -1217,7 +1217,7 @@ static void do_curve_key(Scene *scene, Object *ob, Key *key, char *out, const in
                                        remain = step;
                                }
 
-                               count = MIN2(remain, estep);
+                               count = mini(remain, estep);
                                if (mode == KEY_MODE_BEZTRIPLE) {
                                        count += 3 - count % 3;
                                }
@@ -1573,7 +1573,7 @@ void key_to_latt(KeyBlock *kb, Lattice *lt)
        fp = kb->data;
 
        tot = lt->pntsu * lt->pntsv * lt->pntsw;
-       tot = MIN2(kb->totelem, tot);
+       tot = mini(kb->totelem, tot);
 
        for (a = 0; a < tot; a++, fp += 3, bp++) {
                copy_v3_v3(bp->vec, fp);
@@ -1645,7 +1645,7 @@ void key_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb)
 
        tot = BKE_nurbList_verts_count(nurb);
 
-       tot = MIN2(kb->totelem, tot);
+       tot = mini(kb->totelem, tot);
 
        while (nu && tot > 0) {
 
@@ -1713,7 +1713,7 @@ void key_to_mesh(KeyBlock *kb, Mesh *me)
        mvert = me->mvert;
        fp = kb->data;
 
-       tot = MIN2(kb->totelem, me->totvert);
+       tot = mini(kb->totelem, me->totvert);
 
        for (a = 0; a < tot; a++, fp += 3, mvert++) {
                copy_v3_v3(mvert->co, fp);
index dfa3582cee89a50aa2e2690a3b92471bb795cf0f..5dfecfcb7171a866e57d555d19de40a6de7b7cb1 100644 (file)
@@ -2700,7 +2700,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob)
                                if (pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID) == 0) {
                                        scene->physics_settings.quick_cache_step =
                                                scene->physics_settings.quick_cache_step ?
-                                               MIN2(scene->physics_settings.quick_cache_step, pid->cache->step) :
+                                               mini(scene->physics_settings.quick_cache_step, pid->cache->step) :
                                                pid->cache->step;
                                }
                        }
index 64920df6e2032b1d181a7d1fce6b3116475e6164..726127fdcad1178177e6bfce45e6e8903363b552 100644 (file)
@@ -123,12 +123,12 @@ void *BM_iter_as_arrayN(BMesh *bm, const char itype, void *data, int *r_len)
        if (BM_iter_init(&iter, bm, itype, data) && iter.count > 0) {
                BMElem *ele;
                BMElem **array = MEM_mallocN(sizeof(ele) * iter.count, __func__);
-               int i;
+               int i = 0;
 
                *r_len = iter.count;  /* set before iterating */
 
-               for (ele = BM_iter_step(&iter), i = 0; ele; ele = BM_iter_step(&iter), i++) {
-                       array[i] = ele;
+               while ((ele = BM_iter_step(&iter))) {
+                       array[i++] = ele;
                }
                return array;
        }
index d36c0bbaf4a8246a4d29dcf72bb49a0ef99d5684..4c1c377cb9f7f988b7e784bca4a0e0acf0c40b03 100644 (file)
@@ -1659,8 +1659,9 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value)
                IDP_Int(idprop) = value;
                rna_idproperty_touch(idprop);
        }
-       else if (bprop->set)
+       else if (bprop->set) {
                bprop->set(ptr, value);
+       }
        else if (prop->flag & PROP_EDITABLE) {
                IDPropertyTemplate val = {0};
                IDProperty *group;