diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-02 07:13:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-02 07:13:51 +0400 |
commit | 54310b8086e5820049f73f66fde8c92041fdb61a (patch) | |
tree | d609ba2de71e27ae8af41742930fecbf418c2fcd /source/blender | |
parent | d59b4752e432aa1188fe9082a99d3aa6f6d59ab1 (diff) |
bmesh: internal api change, remove BMOElemMapping, its not needed since the values can be stored in the ghash directly.
saves 24 bytes per element (per vertex/edge/face on a 64bit system), for bmesh operators.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api.h | 27 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api_inline.h | 69 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 63 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_extrude.c | 6 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_array.c | 6 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops_call.c | 26 |
7 files changed, 97 insertions, 102 deletions
diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index 24bfcd70d75..3bfb05221ba 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -398,7 +398,7 @@ int BMO_slot_buffer_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot int BMO_slot_map_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name); void BMO_slot_map_insert(BMOperator *op, BMOpSlot *slot, - const void *element, const void *data, const int len); + const void *element, const void *data); /* flags all elements in a mapping. note that the mapping must only have * bmesh elements in it.*/ @@ -452,7 +452,7 @@ typedef struct BMOIter { BMOpSlot *slot; int cur; //for arrays GHashIterator giter; - void *val; + void **val; char restrictmask; /* bitwise '&' with BMHeader.htype */ } BMOIter; @@ -463,15 +463,12 @@ void *BMO_iter_new(BMOIter *iter, const char restrictmask); void *BMO_iter_step(BMOIter *iter); -/* returns a pointer to the key value when iterating over mappings. - * remember for pointer maps this will be a pointer to a pointer.*/ -void *BMO_iter_map_value(BMOIter *iter); +void **BMO_iter_map_value_p(BMOIter *iter); +void *BMO_iter_map_value_ptr(BMOIter *iter); -/* use this for pointer mappings */ -void *BMO_iter_map_value_p(BMOIter *iter); - -/* use this for float mappings */ -float BMO_iter_map_value_f(BMOIter *iter); +float BMO_iter_map_value_float(BMOIter *iter); +int BMO_iter_map_value_int(BMOIter *iter); +bool BMO_iter_map_value_bool(BMOIter *iter); #define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag) \ for (ele = BMO_iter_new(iter, slot_args, slot_name, restrict_flag); ele; ele = BMO_iter_step(iter)) @@ -479,16 +476,6 @@ float BMO_iter_map_value_f(BMOIter *iter); /******************* Inlined Functions********************/ typedef void (*opexec)(BMesh *bm, BMOperator *op); -/* mappings map elements to data, which - * follows the mapping struct in memory. */ -typedef struct BMOElemMapping { - BMHeader *element; - int len; -} BMOElemMapping; - -/* pointer after BMOElemMapping */ -#define BMO_OP_SLOT_MAPPING_DATA(var) (void *)(((BMOElemMapping *)var) + 1) - extern const int BMO_OPSLOT_TYPEINFO[BMO_OP_SLOT_TOTAL_TYPES]; int BMO_opcode_from_opname(const char *opname); diff --git a/source/blender/bmesh/intern/bmesh_operator_api_inline.h b/source/blender/bmesh/intern/bmesh_operator_api_inline.h index 91cd094bf24..77310d958e6 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api_inline.h +++ b/source/blender/bmesh/intern/bmesh_operator_api_inline.h @@ -72,23 +72,26 @@ BLI_INLINE void _bmo_elem_flag_toggle(BMesh *bm, BMFlagLayer *oflags, const shor BLI_INLINE void BMO_slot_map_int_insert(BMOperator *op, BMOpSlot *slot, void *element, const int val) { + union { void *ptr; int val; } t = {NULL}; BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INT); - BMO_slot_map_insert(op, slot, element, &val, sizeof(int)); + BMO_slot_map_insert(op, slot, element, ((t.val = val), t.ptr)); } BLI_INLINE void BMO_slot_map_bool_insert(BMOperator *op, BMOpSlot *slot, void *element, const int val) { + union { void *ptr; int val; } t = {NULL}; BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_BOOL); BLI_assert(val == false || val == true); - BMO_slot_map_insert(op, slot, element, &val, sizeof(int)); + BMO_slot_map_insert(op, slot, element, ((t.val = val), t.ptr)); } BLI_INLINE void BMO_slot_map_float_insert(BMOperator *op, BMOpSlot *slot, void *element, const float val) { + union { void *ptr; float val; } t = {NULL}; BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_FLT); - BMO_slot_map_insert(op, slot, element, &val, sizeof(float)); + BMO_slot_map_insert(op, slot, element, ((t.val = val), t.ptr)); } @@ -101,14 +104,14 @@ BLI_INLINE void BMO_slot_map_ptr_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val) { BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL); - BMO_slot_map_insert(op, slot, element, &val, sizeof(void *)); + BMO_slot_map_insert(op, slot, element, val); } BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val) { BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_ELEM); - BMO_slot_map_insert(op, slot, element, &val, sizeof(void *)); + BMO_slot_map_insert(op, slot, element, val); } @@ -117,7 +120,7 @@ BLI_INLINE void BMO_slot_map_empty_insert(BMOperator *op, BMOpSlot *slot, const void *element) { BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_EMPTY); - BMO_slot_map_insert(op, slot, element, NULL, 0); + BMO_slot_map_insert(op, slot, element, NULL); } BLI_INLINE bool BMO_slot_map_contains(BMOpSlot *slot, const void *element) @@ -126,57 +129,57 @@ BLI_INLINE bool BMO_slot_map_contains(BMOpSlot *slot, const void *element) return BLI_ghash_haskey(slot->data.ghash, element); } -BLI_INLINE void *BMO_slot_map_data_get(BMOpSlot *slot, const void *element) +BLI_INLINE void **BMO_slot_map_data_get(BMOpSlot *slot, const void *element) { - BMOElemMapping *mapping; - BLI_assert(slot->slot_type == BMO_OP_SLOT_MAPPING); - - mapping = (BMOElemMapping *)BLI_ghash_lookup(slot->data.ghash, element); - - if (!mapping) { - return NULL; - } - return mapping + 1; + return BLI_ghash_lookup_p(slot->data.ghash, element); } BLI_INLINE float BMO_slot_map_float_get(BMOpSlot *slot, const void *element) { - float *val; + void **data; BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_FLT); - val = (float *) BMO_slot_map_data_get(slot, element); - if (val) return *val; - - return 0.0f; + data = BMO_slot_map_data_get(slot, element); + if (data) { + return **(float **)data; + } + else { + return 0.0f; + } } BLI_INLINE int BMO_slot_map_int_get(BMOpSlot *slot, const void *element) { - int *val; + void **data; BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INT); - val = (int *) BMO_slot_map_data_get(slot, element); - if (val) return *val; - - return 0; + data = BMO_slot_map_data_get(slot, element); + if (data) { + return **(int **)data; + } + else { + return 0; + } } BLI_INLINE bool BMO_slot_map_bool_get(BMOpSlot *slot, const void *element) { - int *val; + void **data; BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_BOOL); - val = (int *) BMO_slot_map_data_get(slot, element); - BLI_assert(val == NULL || *val == false || *val == true); - if (val) return (bool)*val; - - return false; + data = BMO_slot_map_data_get(slot, element); + if (data) { + return **(int **)data; + } + else { + return false; + } } BLI_INLINE void *BMO_slot_map_ptr_get(BMOpSlot *slot, const void *element) { - void **val = (void **) BMO_slot_map_data_get(slot, element); + void **val = BMO_slot_map_data_get(slot, element); BLI_assert(slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL); if (val) return *val; diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index e0367e9fce9..836001468a2 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -74,7 +74,7 @@ const int BMO_OPSLOT_TYPEINFO[BMO_OP_SLOT_TOTAL_TYPES] = { 0, /* 7: unused */ sizeof(float) * 3, /* 8: BMO_OP_SLOT_VEC */ sizeof(void *), /* 9: BMO_OP_SLOT_ELEMENT_BUF */ - sizeof(BMOElemMapping) /* 10: BMO_OP_SLOT_MAPPING */ + sizeof(void *) /* 10: BMO_OP_SLOT_MAPPING */ }; /* Dummy slot so there is something to return when slot name lookup fails */ @@ -345,19 +345,13 @@ void _bmo_slot_copy(BMOpSlot slot_args_src[BMO_OP_MAX_SLOTS], const char *slot_n } else if (slot_dst->slot_type == BMO_OP_SLOT_MAPPING) { GHashIterator it; - BMOElemMapping *srcmap, *dstmap; - for (BLI_ghashIterator_init(&it, slot_src->data.ghash); - (srcmap = BLI_ghashIterator_getValue(&it)); + BLI_ghashIterator_done(&it) == false; BLI_ghashIterator_step(&it)) { - dstmap = BLI_memarena_alloc(arena_dst, sizeof(*dstmap) + srcmap->len); - - dstmap->element = srcmap->element; - dstmap->len = srcmap->len; - memcpy(BMO_OP_SLOT_MAPPING_DATA(dstmap), BMO_OP_SLOT_MAPPING_DATA(srcmap), srcmap->len); - - BLI_ghash_insert(slot_dst->data.ghash, dstmap->element, dstmap); + void *key = BLI_ghashIterator_getKey(&it); + void *val = BLI_ghashIterator_getValue(&it); + BLI_ghash_insert(slot_dst->data.ghash, key, val); } } else { @@ -631,19 +625,12 @@ int BMO_slot_map_count(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_na * value, it doesn't store a reference to it. */ void BMO_slot_map_insert(BMOperator *op, BMOpSlot *slot, - const void *element, const void *data, const int len) + const void *element, const void *data) { - BMOElemMapping *mapping; BLI_assert(slot->slot_type == BMO_OP_SLOT_MAPPING); BMO_ASSERT_SLOT_IN_OP(slot, op); - mapping = (BMOElemMapping *) BLI_memarena_alloc(op->arena, sizeof(*mapping) + len); - - mapping->element = (BMHeader *) element; - mapping->len = len; - memcpy(BMO_OP_SLOT_MAPPING_DATA(mapping), data, len); - - BLI_ghash_insert(slot->data.ghash, (void *)element, mapping); + BLI_ghash_insert(slot->data.ghash, (void *)element, (void *)data); } #if 0 @@ -1388,11 +1375,8 @@ void *BMO_iter_step(BMOIter *iter) return ele; } else if (slot->slot_type == BMO_OP_SLOT_MAPPING) { - BMOElemMapping *map; void *ret = BLI_ghashIterator_getKey(&iter->giter); - map = BLI_ghashIterator_getValue(&iter->giter); - - iter->val = BMO_OP_SLOT_MAPPING_DATA(map); + iter->val = BLI_ghashIterator_getValue_p(&iter->giter); BLI_ghashIterator_step(&iter->giter); @@ -1406,19 +1390,40 @@ void *BMO_iter_step(BMOIter *iter) } /* used for iterating over mappings */ -void *BMO_iter_map_value(BMOIter *iter) + +/** + * Returns a pointer to the key-value when iterating over mappings. + * remember for pointer maps this will be a pointer to a pointer. + */ +void **BMO_iter_map_value_p(BMOIter *iter) { return iter->val; } -void *BMO_iter_map_value_p(BMOIter *iter) +void *BMO_iter_map_value_ptr(BMOIter *iter) +{ + BLI_assert(ELEM(iter->slot->slot_subtype.map, + BMO_OP_SLOT_SUBTYPE_MAP_ELEM, BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL)); + return iter->val ? *iter->val : NULL; +} + + +float BMO_iter_map_value_float(BMOIter *iter) +{ + BLI_assert(iter->slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_FLT); + return **((float **)iter->val); +} + +int BMO_iter_map_value_int(BMOIter *iter) { - return *((void **)iter->val); + BLI_assert(iter->slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_INT); + return **((int **)iter->val); } -float BMO_iter_map_value_f(BMOIter *iter) +bool BMO_iter_map_value_bool(BMOIter *iter) { - return *((float *)iter->val); + BLI_assert(iter->slot->slot_subtype.map == BMO_OP_SLOT_SUBTYPE_MAP_BOOL); + return **((int **)iter->val); } /* error system */ diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index c6808da1bb8..90c514bfd02 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -170,7 +170,7 @@ void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op) for (e = BMO_iter_new(&siter, dupeop.slots_out, "boundary_map.out", 0); e; e = BMO_iter_step(&siter)) { BMVert *f_verts[4]; - e_new = *(BMEdge **)BMO_iter_map_value(&siter); + e_new = BMO_iter_map_value_ptr(&siter); if (e->l && e->v1 != e->l->v) { f_verts[0] = e->v1; @@ -372,7 +372,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) continue; } - e_new = *(BMEdge **)BMO_iter_map_value(&siter); + e_new = BMO_iter_map_value_ptr(&siter); if (!e_new) { continue; @@ -407,7 +407,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) /* link isolated vert */ for (v = BMO_iter_new(&siter, dupeop.slots_out, "isovert_map.out", 0); v; v = BMO_iter_step(&siter)) { - BMVert *v2 = *((void **)BMO_iter_map_value(&siter)); + BMVert *v2 = BMO_iter_map_value_ptr(&siter); BM_edge_create(bm, v, v2, v->e, BM_CREATE_NO_DOUBLE); } diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index e669585a857..b3b9cecf389 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -921,7 +921,7 @@ void bmo_subdivide_edges_exec(BMesh *bm, BMOperator *op) } if (BMO_elem_flag_test(bm, face, FACE_CUSTOMFILL)) { - pat = BMO_slot_map_data_get(params.slot_custom_patterns, face); + pat = *BMO_slot_map_data_get(params.slot_custom_patterns, face); for (i = 0; i < pat->len; i++) { matched = 1; for (j = 0; j < pat->len; j++) { diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index 7280503bafb..70362227c65 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -199,7 +199,7 @@ static int *find_doubles_index_map(BMesh *bm, BMOperator *dupe_op, /*element type argument doesn't do anything here*/ BMO_ITER (v, &oiter, find_op.slots_out, "targetmap.out", 0) { - v2 = BMO_iter_map_value_p(&oiter); + v2 = BMO_iter_map_value_ptr(&oiter); index_map[BM_elem_index_get(v)] = BM_elem_index_get(v2) + 1; } @@ -272,7 +272,7 @@ static void bm_merge_dm_transform(BMesh *bm, DerivedMesh *dm, float mat[4][4], /* add new merge targets to weld operator */ BMO_ITER (v, &oiter, find_op.slots_out, "targetmap.out", 0) { - v2 = BMO_iter_map_value_p(&oiter); + v2 = BMO_iter_map_value_ptr(&oiter); /* check in case the target vertex (v2) is already marked * for merging */ while ((v3 = BMO_slot_map_elem_get(slot_targetmap, v2))) { @@ -320,7 +320,7 @@ static void merge_first_last(BMesh *bm, slot_targetmap = BMO_slot_get(weld_op->slots_in, "targetmap"); BMO_ITER (v, &oiter, find_op.slots_out, "targetmap.out", 0) { if (!BMO_slot_map_contains(slot_targetmap, v)) { - v2 = BMO_iter_map_value_p(&oiter); + v2 = BMO_iter_map_value_ptr(&oiter); BMO_slot_map_elem_insert(weld_op, slot_targetmap, v, v2); } } diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c index 6c7fc686cc0..ec9f2865582 100644 --- a/source/blender/python/bmesh/bmesh_py_ops_call.c +++ b/source/blender/python/bmesh/bmesh_py_ops_call.c @@ -581,11 +581,11 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) item = PyDict_New(); if (slot_hash) { GHASH_ITER (hash_iter, slot_hash) { - BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); - BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter); + BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); + void *ele_val = BLI_ghashIterator_getValue(&hash_iter); - PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key); - PyObject *py_val = BPy_BMElem_CreatePyObject(bm, *(void **)BMO_OP_SLOT_MAPPING_DATA(ele_val)); + PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key); + PyObject *py_val = BPy_BMElem_CreatePyObject(bm, ele_val); PyDict_SetItem(item, py_key, py_val); Py_DECREF(py_key); @@ -599,11 +599,11 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) item = PyDict_New(); if (slot_hash) { GHASH_ITER (hash_iter, slot_hash) { - BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); - BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter); + BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); + void *ele_val = BLI_ghashIterator_getValue(&hash_iter); PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key); - PyObject *py_val = PyFloat_FromDouble(*(float *)BMO_OP_SLOT_MAPPING_DATA(ele_val)); + PyObject *py_val = PyFloat_FromDouble(*(float *)&ele_val); PyDict_SetItem(item, py_key, py_val); Py_DECREF(py_key); @@ -617,11 +617,11 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) item = PyDict_New(); if (slot_hash) { GHASH_ITER (hash_iter, slot_hash) { - BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); - BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter); + BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); + void *ele_val = BLI_ghashIterator_getValue(&hash_iter); PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key); - PyObject *py_val = PyLong_FromLong(*(int *)BMO_OP_SLOT_MAPPING_DATA(ele_val)); + PyObject *py_val = PyLong_FromLong(*(int *)&ele_val); PyDict_SetItem(item, py_key, py_val); Py_DECREF(py_key); @@ -635,11 +635,11 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) item = PyDict_New(); if (slot_hash) { GHASH_ITER (hash_iter, slot_hash) { - BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); - BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter); + BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter); + void *ele_val = BLI_ghashIterator_getValue(&hash_iter); PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key); - PyObject *py_val = PyBool_FromLong(*(int *)BMO_OP_SLOT_MAPPING_DATA(ele_val)); + PyObject *py_val = PyBool_FromLong(*(int *)&ele_val); PyDict_SetItem(item, py_key, py_val); Py_DECREF(py_key); |