RNA API: reuse property lookups
authorCampbell Barton <ideasman42@gmail.com>
Tue, 17 Feb 2015 02:09:21 +0000 (13:09 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 17 Feb 2015 02:13:59 +0000 (13:13 +1100)
source/blender/editors/object/object_add.c
source/blender/editors/render/render_shading.c
source/blender/editors/space_buttons/buttons_ops.c
source/blender/editors/space_file/file_ops.c
source/blender/editors/space_file/filesel.c
source/blender/editors/transform/transform.c
source/blender/makesrna/intern/rna_access.c
source/blender/windowmanager/intern/wm_operators.c

index 1180c08278369b22d2f9cff27b4245c8c3deeee2..e73b72430ca2c582f2b23a16ca0072653872462e 100644 (file)
@@ -297,18 +297,19 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
 {
        View3D *v3d = CTX_wm_view3d(C);
        unsigned int _layer;
+       PropertyRNA *prop;
 
-       /* Switch to Edit mode? */
-       if (RNA_struct_find_property(op->ptr, "enter_editmode")) { /* optional */
+       /* Switch to Edit mode? optional prop */
+       if ((prop = RNA_struct_find_property(op->ptr, "enter_editmode"))) {
                bool _enter_editmode;
                if (!enter_editmode)
                        enter_editmode = &_enter_editmode;
 
-               if (RNA_struct_property_is_set(op->ptr, "enter_editmode") && enter_editmode)
-                       *enter_editmode = RNA_boolean_get(op->ptr, "enter_editmode");
+               if (RNA_property_is_set(op->ptr, prop) && enter_editmode)
+                       *enter_editmode = RNA_property_boolean_get(op->ptr, prop);
                else {
                        *enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0;
-                       RNA_boolean_set(op->ptr, "enter_editmode", *enter_editmode);
+                       RNA_property_boolean_set(op->ptr, prop, *enter_editmode);
                }
        }
 
@@ -318,8 +319,9 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
                if (!layer)
                        layer = &_layer;
 
-               if (RNA_struct_property_is_set(op->ptr, "layers")) {
-                       RNA_boolean_get_array(op->ptr, "layers", layer_values);
+               prop = RNA_struct_find_property(op->ptr, "layers");
+               if (RNA_property_is_set(op->ptr, prop)) {
+                       RNA_property_boolean_get_array(op->ptr, prop, layer_values);
                        *layer = 0;
                        for (a = 0; a < 20; a++) {
                                if (layer_values[a])
@@ -332,7 +334,7 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
                        for (a = 0; a < 20; a++) {
                                layer_values[a] = *layer & (1 << a);
                        }
-                       RNA_boolean_set_array(op->ptr, "layers", layer_values);
+                       RNA_property_boolean_set_array(op->ptr, prop, layer_values);
                }
 
                /* in local view we additionally add local view layers,
index 94a3defa95a2f4e2804365b4456a785be2fb953e..ff90f48d705ebbdf9abbb097f40ba2df3a704d10 100644 (file)
@@ -1386,11 +1386,15 @@ void TEXTURE_OT_slot_move(wmOperatorType *ot)
 
 static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, const char imtype)
 {
+       PropertyRNA *prop;
        float layout[12];
-       if (RNA_struct_find_property(op->ptr, "layout") )
-               RNA_float_get_array(op->ptr, "layout", layout);
-       else
+
+       if ((prop = RNA_struct_find_property(op->ptr, "layout"))) {
+               RNA_property_float_get_array(op->ptr, prop, layout);
+       }
+       else {
                memcpy(layout, default_envmap_layout, sizeof(layout));
+       }
 
        if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, layout)) {
                return OPERATOR_FINISHED;
index 0b643cd78583aeabafbe86cd67eb60c1a28aef8c..ba0c22a4ade9db654e32033dae7d8253b52abee9 100644 (file)
@@ -205,6 +205,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                return OPERATOR_CANCELLED;
        }
        else {
+               PropertyRNA *prop_relpath;
                const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
                fbo = MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
                fbo->ptr = ptr;
@@ -216,10 +217,10 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
                /* normally ED_fileselect_get_params would handle this but we need to because of stupid
                 * user-prefs exception - campbell */
-               if (RNA_struct_find_property(op->ptr, "relative_path")) {
-                       if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
+               if ((prop_relpath = RNA_struct_find_property(op->ptr, "relative_path"))) {
+                       if (!RNA_property_is_set(op->ptr, prop_relpath)) {
                                /* annoying exception!, if were dealing with the user prefs, default relative to be off */
-                               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS && (ptr.data != &U));
+                               RNA_property_boolean_set(op->ptr, prop_relpath, U.flag & USER_RELPATHS && (ptr.data != &U));
                        }
                }
                WM_event_add_fileselect(C, op);
index fe158633439c067362fb6e2e6d4ee1a76105701e..9e7adaa2de551a04b68d676d3cb4788b9ac5a614 100644 (file)
@@ -461,12 +461,13 @@ void FILE_OT_select_all_toggle(wmOperatorType *ot)
 static int bookmark_select_exec(bContext *C, wmOperator *op)
 {
        SpaceFile *sfile = CTX_wm_space_file(C);
+       PropertyRNA *prop;
 
-       if (RNA_struct_find_property(op->ptr, "dir")) {
+       if ((prop = RNA_struct_find_property(op->ptr, "dir"))) {
                char entry[256];
                FileSelectParams *params = sfile->params;
 
-               RNA_string_get(op->ptr, "dir", entry);
+               RNA_property_string_get(op->ptr, prop, entry);
                BLI_strncpy(params->dir, entry, sizeof(params->dir));
                BLI_cleanup_dir(G.main->name, params->dir);
                ED_file_change_dir(C, true);
@@ -830,57 +831,59 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
 
 void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
 {
+       PropertyRNA *prop;
+
        BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */
-       if (RNA_struct_find_property(op->ptr, "relative_path")) {
-               if (RNA_boolean_get(op->ptr, "relative_path")) {
+
+       if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
+               if (RNA_property_boolean_get(op->ptr, prop)) {
                        BLI_path_rel(filepath, G.main->name);
                }
        }
 
-       if (RNA_struct_find_property(op->ptr, "filename")) {
-               RNA_string_set(op->ptr, "filename", sfile->params->file);
+       if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
+               RNA_property_string_set(op->ptr, prop, sfile->params->file);
        }
-       if (RNA_struct_find_property(op->ptr, "directory")) {
-               RNA_string_set(op->ptr, "directory", sfile->params->dir);
+       if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
+               RNA_property_string_set(op->ptr, prop, sfile->params->dir);
        }
-       if (RNA_struct_find_property(op->ptr, "filepath")) {
-               RNA_string_set(op->ptr, "filepath", filepath);
+       if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
+               RNA_property_string_set(op->ptr, prop, filepath);
        }
        
        /* some ops have multiple files to select */
        /* this is called on operators check() so clear collections first since
         * they may be already set. */
        {
-               PointerRNA itemptr;
-               PropertyRNA *prop_files = RNA_struct_find_property(op->ptr, "files");
-               PropertyRNA *prop_dirs = RNA_struct_find_property(op->ptr, "dirs");
                int i, numfiles = filelist_numfiles(sfile->files);
 
-               if (prop_files) {
+               if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
+                       PointerRNA itemptr;
                        int num_files = 0;
-                       RNA_property_collection_clear(op->ptr, prop_files);
+                       RNA_property_collection_clear(op->ptr, prop);
                        for (i = 0; i < numfiles; i++) {
                                if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
                                        struct direntry *file = filelist_file(sfile->files, i);
-                                       RNA_property_collection_add(op->ptr, prop_files, &itemptr);
+                                       RNA_property_collection_add(op->ptr, prop, &itemptr);
                                        RNA_string_set(&itemptr, "name", file->relname);
                                        num_files++;
                                }
                        }
                        /* make sure the file specified in the filename button is added even if no files selected */
                        if (0 == num_files) {
-                               RNA_property_collection_add(op->ptr, prop_files, &itemptr);
+                               RNA_property_collection_add(op->ptr, prop, &itemptr);
                                RNA_string_set(&itemptr, "name", sfile->params->file);
                        }
                }
 
-               if (prop_dirs) {
+               if ((prop = RNA_struct_find_property(op->ptr, "dirs"))) {
+                       PointerRNA itemptr;
                        int num_dirs = 0;
-                       RNA_property_collection_clear(op->ptr, prop_dirs);
+                       RNA_property_collection_clear(op->ptr, prop);
                        for (i = 0; i < numfiles; i++) {
                                if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) {
                                        struct direntry *file = filelist_file(sfile->files, i);
-                                       RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
+                                       RNA_property_collection_add(op->ptr, prop, &itemptr);
                                        RNA_string_set(&itemptr, "name", file->relname);
                                        num_dirs++;
                                }
@@ -888,7 +891,7 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
                        
                        /* make sure the directory specified in the button is added even if no directory selected */
                        if (0 == num_dirs) {
-                               RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
+                               RNA_property_collection_add(op->ptr, prop, &itemptr);
                                RNA_string_set(&itemptr, "name", sfile->params->dir);
                        }
                }
@@ -952,8 +955,9 @@ void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
 bool file_draw_check_exists(SpaceFile *sfile)
 {
        if (sfile->op) { /* fails on reload */
-               if (RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
-                       if (RNA_boolean_get(sfile->op->ptr, "check_existing")) {
+               PropertyRNA *prop;
+               if ((prop = RNA_struct_find_property(sfile->op->ptr, "check_existing"))) {
+                       if (RNA_property_boolean_get(sfile->op->ptr, prop)) {
                                char filepath[FILE_MAX];
                                BLI_join_dirfile(filepath, sizeof(filepath), sfile->params->dir, sfile->params->file);
                                if (BLI_is_file(filepath)) {
@@ -1291,6 +1295,7 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
        char name[FILE_MAXFILE];
        char path[FILE_MAX];
        int generate_name = 1;
+       PropertyRNA *prop;
 
        wmWindowManager *wm = CTX_wm_manager(C);
        SpaceFile *sfile = CTX_wm_space_file(C);
@@ -1302,8 +1307,8 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
        
        path[0] = '\0';
 
-       if (RNA_struct_find_property(op->ptr, "directory")) {
-               RNA_string_get(op->ptr, "directory", path);
+       if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
+               RNA_property_string_get(op->ptr, prop, path);
                if (path[0] != '\0') generate_name = 0;
        }
 
index 761249e79790439f5fb63c5cba2c6e87c735569a..3206a0ff89b22ca2bec1e9738e54105cf81ec079 100644 (file)
@@ -117,10 +117,12 @@ short ED_fileselect_set_params(SpaceFile *sfile)
 
                BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title));
 
-               if (RNA_struct_find_property(op->ptr, "filemode"))
-                       params->type = RNA_int_get(op->ptr, "filemode");
-               else
+               if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) {
+                       params->type = RNA_property_int_get(op->ptr, prop);
+               }
+               else {
                        params->type = FILE_SPECIAL;
+               }
 
                if (is_filepath && RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
                        char name[FILE_MAX];
@@ -210,8 +212,9 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                        params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
                }
 
-               if (RNA_struct_find_property(op->ptr, "display_type"))
-                       params->display = RNA_enum_get(op->ptr, "display_type");
+               if ((prop = RNA_struct_find_property(op->ptr, "display_type"))) {
+                       params->display = RNA_property_enum_get(op->ptr, prop);
+               }
 
                if (params->display == FILE_DEFAULTDISPLAY) {
                        if (U.uiflag & USER_SHOW_THUMBNAILS) {
@@ -226,8 +229,10 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                }
 
                if (is_relative_path) {
-                       if (!RNA_struct_property_is_set_ex(op->ptr, "relative_path", false)) {
-                               RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+                       if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
+                               if (!RNA_property_is_set_ex(op->ptr, prop, false)) {
+                                       RNA_property_boolean_set(op->ptr, prop, U.flag & USER_RELPATHS);
+                               }
                        }
                }
        }
index 193bcbb369105d8b637f6a13b80fa7c9d9695c06..58ef2958f3732ecafe6491cf38a5b9c37415a81d 100644 (file)
@@ -1974,8 +1974,8 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
                }
        }
        
-       if (RNA_struct_find_property(op->ptr, "proportional")) {
-               RNA_enum_set(op->ptr, "proportional", proportional);
+       if ((prop = RNA_struct_find_property(op->ptr, "proportional"))) {
+               RNA_property_enum_set(op->ptr, prop, proportional);
                RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
                RNA_float_set(op->ptr, "proportional_size", t->prop_size);
        }
index 7096060e73b106678b28332812edef65eb76edd3..7a2bd83a1c86599287586ad59630ed977d6fb21c 100644 (file)
@@ -4740,8 +4740,9 @@ char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
                /* this may not be an ID at all, check for simple when pointer owns property.
                 * TODO, more complex nested case */
                if (!RNA_struct_is_ID(ptr->type)) {
-                       if (RNA_struct_find_property(ptr, RNA_property_identifier(prop)) == prop) {
-                               data_path = BLI_strdup(RNA_property_identifier(prop));
+                       const char *prop_identifier = RNA_property_identifier(prop);
+                       if (RNA_struct_find_property(ptr, prop_identifier) == prop) {
+                               data_path = BLI_strdup(prop_identifier);
                        }
                }
        }
index c0f8709b0f7d3d7de7a0d80373e74603d022c6fc..1dc719deb2b7c4a84ccba86cfe540bbe999ca442 100644 (file)
@@ -3171,14 +3171,16 @@ static int border_apply_rect(wmOperator *op)
 
 static int border_apply(bContext *C, wmOperator *op, int gesture_mode)
 {
+       PropertyRNA *prop;
+
        int retval;
 
        if (!border_apply_rect(op))
                return 0;
        
        /* XXX weak; border should be configured for this without reading event types */
-       if (RNA_struct_find_property(op->ptr, "gesture_mode")) {
-               RNA_int_set(op->ptr, "gesture_mode", gesture_mode);
+       if ((prop = RNA_struct_find_property(op->ptr, "gesture_mode"))) {
+               RNA_property_int_set(op->ptr, prop, gesture_mode);
        }
 
        retval = op->type->exec(C, op);
@@ -3498,6 +3500,8 @@ void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
 
 int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
+       PropertyRNA *prop;
+
        op->customdata = WM_gesture_new(C, event, WM_GESTURE_LASSO);
        
        /* add modal handler */
@@ -3505,8 +3509,8 @@ int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
        
        wm_gesture_tag_redraw(C);
        
-       if (RNA_struct_find_property(op->ptr, "cursor")) {
-               WM_cursor_modal_set(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
+       if ((prop = RNA_struct_find_property(op->ptr, "cursor"))) {
+               WM_cursor_modal_set(CTX_wm_window(C), RNA_property_int_get(op->ptr, prop));
        }
        
        return OPERATOR_RUNNING_MODAL;
@@ -3514,6 +3518,8 @@ int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 int WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
+       PropertyRNA *prop;
+
        op->customdata = WM_gesture_new(C, event, WM_GESTURE_LINES);
        
        /* add modal handler */
@@ -3521,8 +3527,8 @@ int WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
        
        wm_gesture_tag_redraw(C);
        
-       if (RNA_struct_find_property(op->ptr, "cursor")) {
-               WM_cursor_modal_set(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
+       if ((prop = RNA_struct_find_property(op->ptr, "cursor"))) {
+               WM_cursor_modal_set(CTX_wm_window(C), RNA_property_int_get(op->ptr, prop));
        }
        
        return OPERATOR_RUNNING_MODAL;
@@ -3728,6 +3734,8 @@ static int straightline_apply(bContext *C, wmOperator *op)
 
 int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
+       PropertyRNA *prop;
+
        op->customdata = WM_gesture_new(C, event, WM_GESTURE_STRAIGHTLINE);
        
        /* add modal handler */
@@ -3735,8 +3743,8 @@ int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *e
        
        wm_gesture_tag_redraw(C);
        
-       if (RNA_struct_find_property(op->ptr, "cursor")) {
-               WM_cursor_modal_set(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
+       if ((prop = RNA_struct_find_property(op->ptr, "cursor"))) {
+               WM_cursor_modal_set(CTX_wm_window(C), RNA_property_int_get(op->ptr, prop));
        }
                
        return OPERATOR_RUNNING_MODAL;