[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51169] trunk/blender: code cleanup: reduce change the size of some float vectors that were bigger then they needed to be .

Campbell Barton ideasman42 at gmail.com
Mon Oct 8 09:08:30 CEST 2012


Revision: 51169
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51169
Author:   campbellbarton
Date:     2012-10-08 07:08:29 +0000 (Mon, 08 Oct 2012)
Log Message:
-----------
code cleanup: reduce change the size of some float vectors that were bigger then they needed to be.

update to clang_array_check.py - parse function definitions lazily for some speedup.

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

Modified: trunk/blender/build_files/cmake/clang_array_check.py
===================================================================
--- trunk/blender/build_files/cmake/clang_array_check.py	2012-10-08 06:38:34 UTC (rev 51168)
+++ trunk/blender/build_files/cmake/clang_array_check.py	2012-10-08 07:08:29 UTC (rev 51169)
@@ -19,12 +19,15 @@
 
 """
 
+# 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 @@
     "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 @@
     "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 @@
 # 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 @@
     # 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 @@
 # -----------------------------------------------------------------------------
 _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 @@
         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 @@
                             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 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

Modified: trunk/blender/source/blender/editors/interface/interface_ops.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_ops.c	2012-10-08 06:38:34 UTC (rev 51168)
+++ trunk/blender/source/blender/editors/interface/interface_ops.c	2012-10-08 07:08:29 UTC (rev 51169)
@@ -216,7 +216,7 @@
 /* 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);
 }

Modified: trunk/blender/source/blender/editors/mesh/editmesh_bvh.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_bvh.c	2012-10-08 06:38:34 UTC (rev 51168)
+++ trunk/blender/source/blender/editors/mesh/editmesh_bvh.c	2012-10-08 07:08:29 UTC (rev 51169)
@@ -371,9 +371,9 @@
 }
 #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 @@
 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];

Modified: trunk/blender/source/blender/editors/mesh/editmesh_rip.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_rip.c	2012-10-08 06:38:34 UTC (rev 51168)
+++ trunk/blender/source/blender/editors/mesh/editmesh_rip.c	2012-10-08 07:08:29 UTC (rev 51169)
@@ -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);

Modified: trunk/blender/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_tools.c	2012-10-08 06:38:34 UTC (rev 51168)
+++ trunk/blender/source/blender/editors/mesh/editmesh_tools.c	2012-10-08 07:08:29 UTC (rev 51169)
@@ -765,7 +765,7 @@
 		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))

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2012-10-08 06:38:34 UTC (rev 51168)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2012-10-08 07:08:29 UTC (rev 51169)
@@ -51,7 +51,7 @@
 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]);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list