Fix another cases where painting long brush strokes with small radius was slowed
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 May 2013 14:37:01 +0000 (14:37 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 May 2013 14:37:01 +0000 (14:37 +0000)
down, this time by the operator properties getting converted to a string for
display in the info window.

With 1000+ stroke points this can get slow, and takes up too much space anyway,
so now it's (somewhat arbitrarily) limited to printing only 10 points.

source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_access.c
source/blender/python/intern/bpy_rna.c
source/blender/windowmanager/intern/wm_operators.c

index 45613f2083f69f6485289548cd5982d813801781..9aeb1166aa602b203597efc7af54e7dcdbec0512 100644 (file)
@@ -1031,15 +1031,18 @@ bool RNA_property_is_unlink(PropertyRNA *prop);
 void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier);
 
 /* python compatible string representation of this property, (must be freed!) */
-char *RNA_property_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index);
+char *RNA_property_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length);
 char *RNA_pointer_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop);
 char *RNA_pointer_as_string_keywords_ex(struct bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
                                         const short skip_optional_value, const short all_args,
+                                        const int max_prop_length,
                                         PropertyRNA *iterprop);
 char *RNA_pointer_as_string_keywords(struct bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
-                                     const short skip_optional_value, const short all_args);
+                                     const short skip_optional_value, const short all_args,
+                                     const int max_prop_length);
 char *RNA_function_as_string_keywords(struct bContext *C, FunctionRNA *func, PointerRNA *ptr_default,
-                                      const short as_function, const short all_args);
+                                      const short as_function, const short all_args,
+                                      const int max_prop_length);
 
 /* Function */
 
index beab5011f2ea96b7494f9ee095c3e255c1b8326e..32aeaebee583f707f562d4003bbb257bafb6ce77 100644 (file)
@@ -4983,7 +4983,7 @@ static char *rna_pointer_as_string__idprop(bContext *C, PointerRNA *ptr)
                        BLI_dynstr_append(dynstr, ", ");
                first_time = 0;
                
-               cstring = RNA_property_as_string(C, ptr, prop, -1);
+               cstring = RNA_property_as_string(C, ptr, prop, -1, INT_MAX);
                BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
                MEM_freeN(cstring);
        }
@@ -5023,6 +5023,7 @@ char *RNA_pointer_as_string(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *p
 /* context and ptr_default can be NULL */
 char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
                                         const short as_function, const short all_args,
+                                                                               const int max_prop_length,
                                         PropertyRNA *iterprop)
 {
        const char *arg_name = NULL;
@@ -5071,7 +5072,7 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA
                                }
                        }
                        else {
-                               buf = RNA_property_as_string(C, ptr, prop, -1);
+                               buf = RNA_property_as_string(C, ptr, prop, -1, max_prop_length);
                        }
 
                        ok = TRUE;
@@ -5082,7 +5083,7 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA
                                prop_default = RNA_struct_find_property(ptr_default, arg_name);
 
                                if (prop_default) {
-                                       buf_default = RNA_property_as_string(C, ptr_default, prop_default, -1);
+                                       buf_default = RNA_property_as_string(C, ptr_default, prop_default, -1, max_prop_length);
 
                                        if (strcmp(buf, buf_default) == 0)
                                                ok = FALSE;  /* values match, don't bother printing */
@@ -5106,18 +5107,20 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA
 }
 
 char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default,
-                                     const short as_function, const short all_args)
+                                     const short as_function, const short all_args,
+                                     const int max_prop_length)
 {
        PropertyRNA *iterprop;
 
        iterprop = RNA_struct_iterator_property(ptr->type);
 
        return RNA_pointer_as_string_keywords_ex(C, ptr, ptr_default, as_function, all_args,
-                                                iterprop);
+                                                max_prop_length, iterprop);
 }
 
 char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA *ptr_default,
-                                      const short as_function, const short all_args)
+                                      const short as_function, const short all_args,
+                                      const int max_prop_length)
 {
        PointerRNA funcptr;
        PropertyRNA *iterprop;
@@ -5129,7 +5132,7 @@ char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA
        RNA_struct_iterator_property(funcptr.type);
 
        return RNA_pointer_as_string_keywords_ex(C, &funcptr, ptr_default, as_function, all_args,
-                                                iterprop);
+                                                max_prop_length, iterprop);
 }
 
 static const char *bool_as_py_string(const int var)
@@ -5137,7 +5140,7 @@ static const char *bool_as_py_string(const int var)
        return var ? "True" : "False";
 }
 
-char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index)
+char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
 {
        int type = RNA_property_type(prop);
        int len = RNA_property_array_length(ptr, prop);
@@ -5277,18 +5280,18 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in
                }
                case PROP_COLLECTION:
                {
-                       int first_time = 1;
+                       int i = 0;
                        CollectionPropertyIterator collect_iter;
                        BLI_dynstr_append(dynstr, "[");
 
-                       for (RNA_property_collection_begin(ptr, prop, &collect_iter); collect_iter.valid;
-                            RNA_property_collection_next(&collect_iter))
+                       for (RNA_property_collection_begin(ptr, prop, &collect_iter);
+                            (i < max_prop_length) && collect_iter.valid;
+                            RNA_property_collection_next(&collect_iter), i++)
                        {
                                PointerRNA itemptr = collect_iter.ptr;
 
-                               if (first_time == 0)
+                               if (i != 0)
                                        BLI_dynstr_append(dynstr, ", ");
-                               first_time = 0;
 
                                /* now get every prop of the collection */
                                cstring = RNA_pointer_as_string(C, ptr, prop, &itemptr);
index a0b2cd639bb7837c17d994aa5ef668f69d16c257..53340437e07db482142d7136d72843653bf34f45 100644 (file)
@@ -5318,7 +5318,7 @@ static PyObject *pyrna_func_doc_get(BPy_FunctionRNA *self, void *UNUSED(closure)
        PyObject *ret;
        char *args;
 
-       args = RNA_function_as_string_keywords(NULL, self->func, NULL, true, true);
+       args = RNA_function_as_string_keywords(NULL, self->func, NULL, true, true, INT_MAX);
 
        ret = PyUnicode_FromFormat("%.200s.%.200s(%.200s)\n%s",
                                   RNA_struct_identifier(self->ptr.type),
index c204554cc6c64f62c6a71012b7be9819998ed4bd..4dce99dd0177850dcba9cfce08e0d69068f8e7a1 100644 (file)
@@ -541,6 +541,9 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i
        char *cstring;
        char *cstring_args;
 
+       /* arbitrary, but can get huge string with stroke painting otherwise */
+       int max_prop_length = 10;
+
        /* only to get the orginal props for comparisons */
        PointerRNA opptr_default;
 
@@ -554,7 +557,8 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i
        WM_operator_py_idname(idname_py, ot->idname);
        BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
 
-       cstring_args = RNA_pointer_as_string_keywords(C, opptr, &opptr_default, FALSE, all_args);
+       cstring_args = RNA_pointer_as_string_keywords(C, opptr, &opptr_default, FALSE,
+                                                     all_args, max_prop_length);
        BLI_dynstr_append(dynstr, cstring_args);
        MEM_freeN(cstring_args);
 
@@ -737,7 +741,7 @@ char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, i
                return NULL;
        }
 
-       rhs = RNA_property_as_string(C, ptr, prop, index);
+       rhs = RNA_property_as_string(C, ptr, prop, index, INT_MAX);
        if (!rhs) {
                MEM_freeN(lhs);
                return NULL;