36#define USE_ARRAY_STORE
43# define ARRAY_CHUNK_SIZE 32
91# define STATE_COMPACT(uf, id, len) \
93 BLI_assert(create == ((uf)->store.id == nullptr)); \
95 BArrayState *state_reference = uf_ref ? uf_ref->store.id : nullptr; \
96 const size_t stride = sizeof(*(uf)->id); \
97 BArrayStore *bs = BLI_array_store_at_size_ensure( \
98 &uf_arraystore.bs_stride, stride, ARRAY_CHUNK_SIZE); \
99 (uf)->store.id = BLI_array_store_state_add( \
100 bs, (uf)->id, size_t(len) * stride, state_reference); \
103 MEM_freeN((uf)->id); \
104 (uf)->id = nullptr; \
129 size_t size_expanded_prev, size_compacted_prev;
131 &
uf_arraystore.bs_stride, &size_expanded_prev, &size_compacted_prev);
138 size_t size_expanded, size_compacted;
142 const double percent_total = size_expanded ?
143 ((
double(size_compacted) /
double(size_expanded)) * 100.0) :
146 size_t size_expanded_step = size_expanded - size_expanded_prev;
147 size_t size_compacted_step = size_compacted - size_compacted_prev;
148 const double percent_step = size_expanded_step ?
149 ((
double(size_compacted_step) /
double(size_expanded_step)) *
153 printf(
"overall memory use: %.8f%% of expanded size\n", percent_total);
154 printf(
"step memory use: %.8f%% of expanded size\n", percent_step);
169# define STATE_EXPAND(uf, id, len) \
170 if ((uf)->store.id) { \
171 const size_t stride = sizeof(*(uf)->id); \
172 BArrayState *state = (uf)->store.id; \
174 *(void **)&(uf)->id = BLI_array_store_state_data_get_alloc(state, &state_len); \
175 BLI_assert((len) == (state_len / stride)); \
176 UNUSED_VARS_NDEBUG(stride); \
188# define STATE_FREE(uf, id) \
189 if ((uf)->store.id) { \
190 const size_t stride = sizeof(*(uf)->id); \
191 BArrayStore *bs = BLI_array_store_at_size_get(&uf_arraystore.bs_stride, stride); \
192 BArrayState *state = (uf)->store.id; \
193 BLI_array_store_state_remove(bs, state); \
194 (uf)->store.id = nullptr; \
209 printf(
"editfont undo store: freeing all data!\n");
226#ifdef USE_ARRAY_STORE
230 final_size =
sizeof(*ef->
textbuf) * (uf->
len + 1);
241#ifdef USE_ARRAY_STORE
257 final_size =
sizeof(*uf->
textbuf) * (ef->
len + 1);
270#ifdef USE_ARRAY_STORE
285 uf->
undo_size = mem_used_prev < mem_used_curr ? mem_used_curr - mem_used_prev :
sizeof(
UndoFont);
292#ifdef USE_ARRAY_STORE
405 ut->
name =
"Edit Font";
Scene * CTX_data_scene(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_edit_object_get(const ViewLayer *view_layer)
@ UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
Efficient in-memory storage of multiple similar arrays.
void BLI_array_store_at_size_clear(struct BArrayStore_AtSize *bs_stride)
void BLI_array_store_at_size_calc_memory_usage(const struct BArrayStore_AtSize *bs_stride, size_t *r_size_expanded, size_t *r_size_compacted)
Generic array manipulation API.
#define BLI_array_is_zeroed(arr, arr_len)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
struct LinkData * BLI_genericNodeN(void *data)
typedef double(DMatrix)[4][4]
void DEG_id_tag_update(ID *id, unsigned int flags)
Object is a sort of wrapper for general info.
void ED_undo_object_set_active_or_warn(Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
void ED_undo_object_editmode_restore_helper(Scene *scene, ViewLayer *view_layer, Object **object_array, uint object_array_len, uint object_array_stride)
void ED_undo_object_editmode_validate_scene_from_windows(wmWindowManager *wm, const Scene *scene_ref, Scene **scene_p, ViewLayer **view_layer_p)
Read Guarded memory(de)allocation.
#define STATE_COMPACT(uf, id, len)
static Object * editfont_object_from_context(bContext *C)
static bool font_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_p)
#define STATE_FREE(uf, id)
static void uf_arraystore_expand(UndoFont *uf)
static void * undofont_from_editfont(UndoFont *uf, Curve *cu)
static void font_undosys_step_decode(bContext *C, Main *bmain, UndoStep *us_p, const eUndoStepDir, bool)
static void font_undosys_step_free(UndoStep *us_p)
static void uf_arraystore_expand_clear(UndoFont *um)
static void undofont_free_data(UndoFont *uf)
static void uf_arraystore_compact_with_info(UndoFont *um, const UndoFont *uf_ref)
static void uf_arraystore_compact(UndoFont *um, const UndoFont *uf_ref)
static void uf_arraystore_free(UndoFont *uf)
static struct @318 uf_arraystore
static bool font_undosys_poll(bContext *C)
static void font_undosys_foreach_ID_ref(UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
BArrayStore_AtSize bs_stride
void ED_font_undosys_type(UndoType *ut)
static void undofont_to_editfont(UndoFont *uf, Curve *cu)
#define STATE_EXPAND(uf, id, len)
static void uf_arraystore_compact_ex(UndoFont *uf, const UndoFont *uf_ref, bool create)
void *(* MEM_mallocN)(size_t len, const char *str)
size_t(* MEM_get_memory_in_use)(void)
void MEM_freeN(void *vmemh)
struct EditFont * editfont
UndoRefID_Scene scene_ref
UndoRefID_Object obedit_ref
bool is_memfile_undo_flush_needed
BArrayState * textbufinfo
struct UndoFont::@319 store
void(* step_foreach_ID_ref)(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
void(* step_free)(UndoStep *us)
bool(* poll)(struct bContext *C)
void(* step_decode)(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
bool(* step_encode)(bContext *C, Main *bmain, UndoStep *us)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)