diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-08 11:08:29 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-08 11:08:29 +0400 |
commit | 8b7896814f5ee2cea4c43d409f55ff57649c8661 (patch) | |
tree | c9ef81560d80995efdc9dcae68a647e42ec1dc42 | |
parent | 321e9d8011f5d0e200c8206487b3e1253469b552 (diff) |
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.
-rw-r--r-- | build_files/cmake/clang_array_check.py | 84 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_bvh.c | 6 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_rip.c | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 19 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/outliner_draw.c | 2 |
10 files changed, 69 insertions, 54 deletions
diff --git a/build_files/cmake/clang_array_check.py b/build_files/cmake/clang_array_check.py index df45648f975..3070c27f769 100644 --- a/build_files/cmake/clang_array_check.py +++ b/build_files/cmake/clang_array_check.py @@ -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 diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 1ee06b1ff64..e4e2598c494 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -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); } diff --git a/source/blender/editors/mesh/editmesh_bvh.c b/source/blender/editors/mesh/editmesh_bvh.c index c249d764ac1..e84fa90fe5c 100644 --- a/source/blender/editors/mesh/editmesh_bvh.c +++ b/source/blender/editors/mesh/editmesh_bvh.c @@ -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]; diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index 001d584416f..0b3d178e2e8 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -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); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 0d78d850e74..891e1487781 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -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)) diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 794e7755636..162e2fa15d6 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -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); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 7fabaf7f23d..2ae24db7c33 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -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); } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 3d3e86d2acb..e03c2fbfd21 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 0852378974e..acb906e4a91 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -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 */ diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index e8aa01af6b2..d2e47427b94 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -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 |