code cleanup: reduce change the size of some float vectors that were bigger then...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 8 Oct 2012 07:08:29 +0000 (07:08 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 8 Oct 2012 07:08:29 +0000 (07:08 +0000)
update to clang_array_check.py - parse function definitions lazily for some speedup.

build_files/cmake/clang_array_check.py
source/blender/editors/interface/interface_ops.c
source/blender/editors/mesh/editmesh_bvh.c
source/blender/editors/mesh/editmesh_rip.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/sculpt_paint/paint_intern.h
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_intern.h
source/blender/editors/space_outliner/outliner_draw.c

index df45648f975e243f3ccf97761264637f89d6cd61..3070c27f769675b3dabcaa3c48921ff61db3b6ac 100644 (file)
@@ -19,12 +19,15 @@ Invocation:
 
 """
 
+# delay parsing functions until we need them
+USE_LAZY_INIT = True
+
 # -----------------------------------------------------------------------------
 # predefined function/arg sizes, handy sometimes, but not complete...
 
 defs_precalc = {
-    "glColor3bv":  {0: 3},
-    "glColor4bv":  {0: 4},
+    "glColor3bv": {0: 3},
+    "glColor4bv": {0: 4},
 
     "glColor3ubv": {0: 3},
     "glColor4ubv": {0: 4},
@@ -32,11 +35,11 @@ defs_precalc = {
     "glColor4usv": {0: 3},
     "glColor4usv": {0: 4},
 
-    "glColor3fv":  {0: 3},
-    "glColor4fv":  {0: 4},
+    "glColor3fv": {0: 3},
+    "glColor4fv": {0: 4},
 
-    "glColor3dv":  {0: 3},
-    "glColor4dv":  {0: 4},
+    "glColor3dv": {0: 3},
+    "glColor4dv": {0: 4},
     
     "glVertex2fv": {0: 2},
     "glVertex3fv": {0: 3},
@@ -52,12 +55,12 @@ defs_precalc = {
     "glRasterPos4dv": {0: 4},
     
     "glRasterPos2fv": {0: 2},
-    "glRasterPos3fv": {0: 3},    
+    "glRasterPos3fv": {0: 3},
     "glRasterPos4fv": {0: 4},
     
     "glRasterPos2sv": {0: 2},
-    "glRasterPos3sv": {0: 3},    
-    "glRasterPos4sv": {0: 4},   
+    "glRasterPos3sv": {0: 3},
+    "glRasterPos4sv": {0: 4},
     
     "glTexCoord2fv": {0: 2},
     "glTexCoord3fv": {0: 3},
@@ -112,10 +115,11 @@ args = sys.argv[2:]
 # print(args)
 
 tu = index.parse(sys.argv[1], args)
-print 'Translation unit:', tu.spelling
+print('Translation unit: %s' % tu.spelling)
 
 # -----------------------------------------------------------------------------
 
+
 def function_parm_wash_tokens(parm):
     # print(parm.kind)
     assert parm.kind in (CursorKind.PARM_DECL,
@@ -174,22 +178,21 @@ def parm_size(node_child):
     # print(" ".join([t.spelling for t in tokens]))
     
     # NOT PERFECT CODE, EXTRACT SIZE FROM TOKENS
-    if len(tokens) >= 3: # foo [ 1 ]
-        if ((tokens[-3].kind == TokenKind.PUNCTUATION and tokens[-3].spelling == "[") and
-            (tokens[-2].kind == TokenKind.LITERAL     and tokens[-2].spelling.isdigit()) and
-            (tokens[-1].kind == TokenKind.PUNCTUATION and tokens[-1].spelling == "]")):
+    if len(tokens) >= 3:  # foo [ 1 ]
+        if      ((tokens[-3].kind == TokenKind.PUNCTUATION and tokens[-3].spelling == "[") and
+                 (tokens[-2].kind == TokenKind.LITERAL and tokens[-2].spelling.isdigit()) and
+                 (tokens[-1].kind == TokenKind.PUNCTUATION and tokens[-1].spelling == "]")):
             # ---
             return int(tokens[-2].spelling)
     return -1
 
 
-
 def function_get_arg_sizes(node):
     # Return a dict if (index: size) items
     # {arg_indx: arg_array_size, ... ]
     arg_sizes = {}
 
-    if node.spelling == "BM_vert_create" or 1:
+    if 1:  # node.spelling == "BM_vert_create", for debugging
         node_parms = [node_child for node_child in node.get_children()
                       if node_child.kind == CursorKind.PARM_DECL]
 
@@ -211,11 +214,19 @@ def function_get_arg_sizes(node):
 # -----------------------------------------------------------------------------
 _defs = {}
 
+
 def lookup_function_size_def(func_id):
-    return _defs.get(func_id, ())
+    if USE_LAZY_INIT:
+        result = _defs.get(func_id, {})
+        if type(result) != dict:
+            result = _defs[func_id] = function_get_arg_sizes(result)
+        return result
+    else:
+        return _defs.get(func_id, {})
 
 # -----------------------------------------------------------------------------
 
+
 def file_check_arg_sizes(tu):
     
     # main checking function
@@ -224,7 +235,13 @@ def file_check_arg_sizes(tu):
         Loop over args and validate sizes for args we KNOW the size of.
         """
         assert node.kind == CursorKind.CALL_EXPR
-        # print("---", " <~> ".join([" ".join([t.spelling for t in C.get_tokens()]) for C in node.get_children()]))
+        
+        if 0:
+            print("---",
+                  " <~> ".join(
+                  [" ".join([t.spelling for t in C.get_tokens()])
+                  for C in node.get_children()]
+                  ))
         # print(node.location)
         
         # first child is the function call, skip that.
@@ -283,36 +300,32 @@ def file_check_arg_sizes(tu):
                             if size != -1 and size != 0:
                                 
                                 # nice print!
-                                '''
-                                print("".join([t.spelling for t in func.get_tokens()]),
-                                      i,
-                                      " ".join([t.spelling for t in dec.get_tokens()]))
-                                '''
+                                if 0:
+                                    print("".join([t.spelling for t in func.get_tokens()]),
+                                          i,
+                                          " ".join([t.spelling for t in dec.get_tokens()]))
 
                                 # testing
                                 # size_def = 100
-
-                                if size < size_def:
+                                if size < size_def and size != 1:
                                     location = node.location
                                     print("%s:%d:%d: argument %d is size %d, should be %d" %
                                           (location.file,
                                            location.line,
-                                            location.column,
-                                            i + 1, size, size_def
-                                            ))
-
+                                           location.column,
+                                           i + 1, size, size_def
+                                           ))
 
     # we dont really care what we are looking at, just scan entire file for
     # function calls.
-    
+
     def recursive_func_call_check(node):
-        
         if node.kind == CursorKind.CALL_EXPR:
             validate_arg_size(node)
-        
+
         for c in node.get_children():
             recursive_func_call_check(c)
-    
+
     recursive_func_call_check(tu.cursor)
 
 
@@ -322,7 +335,10 @@ def file_check_arg_sizes(tu):
 def recursive_arg_sizes(node, ):
     # print(node.kind, node.spelling)
     if node.kind == CursorKind.FUNCTION_DECL:
-        args_sizes = function_get_arg_sizes(node)
+        if USE_LAZY_INIT:
+            args_sizes = node
+        else:
+            args_sizes = function_get_arg_sizes(node)
         #if args_sizes:
         #    print(node.spelling, args_sizes)
         _defs[node.spelling] = args_sizes
index 1ee06b1ff64c61a1ea6403954b48647eb0f38347..e4e2598c4949200df91e5211862fc12fddb660db 100644 (file)
@@ -216,7 +216,7 @@ static void eyedropper_color_set(bContext *C, Eyedropper *eye, const float col[3
 /* set sample from accumulated values */
 static void eyedropper_color_set_accum(bContext *C, Eyedropper *eye)
 {
-       float col[4];
+       float col[3];
        mul_v3_v3fl(col, eye->accum_col, 1.0f / (float)eye->accum_tot);
        eyedropper_color_set(C, eye, col);
 }
index c249d764ac16ad691321f3a149225566b414d3e9..e84fa90fe5c55b2fa6d5d73acb3394fcb20afe3a 100644 (file)
@@ -371,9 +371,9 @@ int BMBVH_VertVisible(BMBVHTree *tree, BMEdge *e, RegionView3D *r3d)
 }
 #endif
 
-static BMFace *edge_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], float *hitout, BMEdge *e)
+static BMFace *edge_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], float *r_hitout, BMEdge *e)
 {
-       BMFace *f = BMBVH_RayCast(tree, co, dir, hitout, NULL);
+       BMFace *f = BMBVH_RayCast(tree, co, dir, r_hitout, NULL);
        
        if (f && BM_edge_in_face(f, e))
                return NULL;
@@ -392,7 +392,7 @@ static void scale_point(float c1[3], const float p[3], const float s)
 int BMBVH_EdgeVisible(BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Object *obedit)
 {
        BMFace *f;
-       float co1[3], co2[3], co3[3], dir1[4], dir2[4], dir3[4];
+       float co1[3], co2[3], co3[3], dir1[3], dir2[3], dir3[3];
        float origin[3], invmat[4][4];
        float epsilon = 0.01f; 
        float end[3];
index 001d584416fbe0a95907a3c5523dabc0d6285f9d..0b3d178e2e85a5fc787c496b74d368f02c565cf0 100644 (file)
@@ -59,7 +59,7 @@
 static float edbm_rip_rip_edgedist(ARegion *ar, float mat[][4],
                                    const float co1[3], const float co2[3], const float mvalf[2])
 {
-       float vec1[3], vec2[3];
+       float vec1[2], vec2[2];
 
        ED_view3d_project_float_v2_m4(ar, co1, vec1, mat);
        ED_view3d_project_float_v2_m4(ar, co2, vec2, mat);
index 0d78d850e74c7029962ba4c2bb9c24651bf1b59e..891e148778143bf8e84e535f1dc14ef5bf86ec66 100644 (file)
@@ -765,7 +765,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
                done = FALSE;
                BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
                        if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
-                               float co1[3], co2[3];
+                               float co1[2], co2[2];
 
                                if ((ED_view3d_project_float_object(vc.ar, eed->v1->co, co1, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
                                    (ED_view3d_project_float_object(vc.ar, eed->v2->co, co2, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
index 794e7755636b5730291b74caddd3d0584de02da3..162e2fa15d60b3cbcac2a048921d491692b1b46e 100644 (file)
@@ -51,7 +51,7 @@ struct wmOperator;
 struct wmOperatorType;
 
 /* paint_stroke.c */
-typedef int (*StrokeGetLocation)(struct bContext *C, float location[3], float mouse[2]);
+typedef int (*StrokeGetLocation)(struct bContext *C, float location[3], const float mouse[2]);
 typedef int (*StrokeTestStart)(struct bContext *C, struct wmOperator *op, const float mouse[2]);
 typedef void (*StrokeUpdateStep)(struct bContext *C, struct PaintStroke *stroke, struct PointerRNA *itemptr);
 typedef void (*StrokeDone)(const struct bContext *C, struct PaintStroke *stroke);
index 7fabaf7f23dbbe6207d790e3ff4bd7bf483e8df3..2ae24db7c3338b91a0e227eb2cd2fcbf3a124eef 100644 (file)
@@ -139,13 +139,13 @@ static float event_tablet_data(wmEvent *event, int *pen_flip)
 }
 
 /* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
-static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
+static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, const float mouse_in[2])
 {
        Scene *scene = CTX_data_scene(C);
        Paint *paint = paint_get_active_from_context(C);
        Brush *brush = paint_brush(paint);
        PaintStroke *stroke = op->customdata;
-       float mouse[3];
+       float mouse_out[2];
        PointerRNA itemptr;
        float location[3];
        float pressure;
@@ -159,24 +159,24 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
        if (stroke->vc.obact->sculpt) {
                float delta[2];
 
-               BKE_brush_jitter_pos(scene, brush, mouse_in, mouse);
+               BKE_brush_jitter_pos(scene, brush, mouse_in, mouse_out);
 
                /* XXX: meh, this is round about because
                 * BKE_brush_jitter_pos isn't written in the best way to
                 * be reused here */
                if (brush->flag & BRUSH_JITTER_PRESSURE) {
-                       sub_v2_v2v2(delta, mouse, mouse_in);
+                       sub_v2_v2v2(delta, mouse_out, mouse_in);
                        mul_v2_fl(delta, pressure);
-                       add_v2_v2v2(mouse, mouse_in, delta);
+                       add_v2_v2v2(mouse_out, mouse_in, delta);
                }
        }
        else {
-               copy_v2_v2(mouse, mouse_in);
+               copy_v2_v2(mouse_out, mouse_in);
        }
 
        /* TODO: can remove the if statement once all modes have this */
        if (stroke->get_location)
-               stroke->get_location(C, location, mouse);
+               stroke->get_location(C, location, mouse_out);
        else
                zero_v3(location);
 
@@ -184,12 +184,11 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
        RNA_collection_add(op->ptr, "stroke", &itemptr);
 
        RNA_float_set_array(&itemptr, "location", location);
-       RNA_float_set_array(&itemptr, "mouse", mouse);
+       RNA_float_set_array(&itemptr, "mouse", mouse_out);
        RNA_boolean_set(&itemptr, "pen_flip", pen_flip);
        RNA_float_set(&itemptr, "pressure", pressure);
 
-       stroke->last_mouse_position[0] = mouse[0];
-       stroke->last_mouse_position[1] = mouse[1];
+       copy_v2_v2(stroke->last_mouse_position, mouse_out);
 
        stroke->update_step(C, stroke, &itemptr);
 }
index 3d3e86d2acb4ec4518292a01fbb9a38940dcbb5a..e03c2fbfd21faa856c49cb4ebca423cfcdb30825 100644 (file)
@@ -3738,7 +3738,7 @@ static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
  * (This allows us to ignore the GL depth buffer)
  * Returns 0 if the ray doesn't hit the mesh, non-zero otherwise
  */
-int sculpt_stroke_get_location(bContext *C, float out[3], float mouse[2])
+int sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2])
 {
        ViewContext vc;
        Object *ob;
index 0852378974e2cef9c1d6418a44d1dfe7106a28c5..acb906e4a91c7490e3fb9dab60e3923286a640c7 100644 (file)
@@ -65,7 +65,7 @@ void sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, struct
 void free_sculptsession_deformMats(struct SculptSession *ss);
 
 /* Stroke */
-int sculpt_stroke_get_location(bContext *C, float out[3], float mouse[2]);
+int sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2]);
 
 /* Undo */
 
index e8aa01af6b26c1ccb2f8a48970204dd47fe18d42..d2e47427b94861e1b71d617a9fa1f870a57d9d2a 100644 (file)
@@ -1531,7 +1531,7 @@ static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegio
 {
        TreeElement *te;
        int starty, startx;
-       float col[4];
+       float col[3];
                
        glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once