diff options
Diffstat (limited to 'source/blender/bmesh/intern')
-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 |
3 files changed, 77 insertions, 82 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 */ |