diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-06-08 09:57:34 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-08 12:21:18 +0300 |
commit | 94057b15d1c8fd31d1fb8e8f9b30cb681accfb5c (patch) | |
tree | f1db57634801779f0fb26935f8fc4cca03ca9e58 /source | |
parent | c6864c408bc16e4b7b0e066788fb213c984ff09a (diff) |
3D Text: Store separate arrays for undo data
Don't store maximum length of text per undo step,
or attempt to pack all data in a single array.
Was storing 32766 characters per undo step, irrespective of actual text length.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/curve/editfont_undo.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c index cee10698039..b2a265a415b 100644 --- a/source/blender/editors/curve/editfont_undo.c +++ b/source/blender/editors/curve/editfont_undo.c @@ -40,47 +40,62 @@ #include "ED_curve.h" #include "ED_util.h" -/* TODO, remove */ -#define MAXTEXT 32766 +typedef struct UndoFont { + wchar_t *textbuf; + struct CharInfo *textbufinfo; -static void undoFont_to_editFont(void *strv, void *ecu, void *UNUSED(obdata)) + int len, pos; +} UndoFont; + +static void undoFont_to_editFont(void *uf_v, void *ecu, void *UNUSED(obdata)) { Curve *cu = (Curve *)ecu; EditFont *ef = cu->editfont; - const char *str = strv; + const UndoFont *uf = uf_v; - ef->pos = *((const short *)str); - ef->len = *((const short *)(str + 2)); + size_t final_size; - memcpy(ef->textbuf, str + 4, (ef->len + 1) * sizeof(wchar_t)); - memcpy(ef->textbufinfo, str + 4 + (ef->len + 1) * sizeof(wchar_t), ef->len * sizeof(CharInfo)); + final_size = sizeof(wchar_t) * (uf->len + 1); + memcpy(ef->textbuf, uf->textbuf, final_size); - ef->selstart = ef->selend = 0; + final_size = sizeof(CharInfo) * (uf->len + 1); + memcpy(ef->textbufinfo, uf->textbufinfo, final_size); + + ef->pos = uf->pos; + ef->len = uf->len; + ef->selstart = ef->selend = 0; } static void *editFont_to_undoFont(void *ecu, void *UNUSED(obdata)) { Curve *cu = (Curve *)ecu; EditFont *ef = cu->editfont; - char *str; - /* The undo buffer includes [MAXTEXT+6]=actual string and [MAXTEXT+4]*sizeof(CharInfo)=charinfo */ - str = MEM_callocN((MAXTEXT + 6) * sizeof(wchar_t) + (MAXTEXT + 4) * sizeof(CharInfo), "string undo"); + UndoFont *uf = MEM_callocN(sizeof(*uf), __func__); + + size_t final_size; + + final_size = sizeof(wchar_t) * (ef->len + 1); + uf->textbuf = MEM_mallocN(final_size, __func__); + memcpy(uf->textbuf, ef->textbuf, final_size); - /* Copy the string and string information */ - memcpy(str + 4, ef->textbuf, (ef->len + 1) * sizeof(wchar_t)); - memcpy(str + 4 + (ef->len + 1) * sizeof(wchar_t), ef->textbufinfo, ef->len * sizeof(CharInfo)); + final_size = sizeof(CharInfo) * (ef->len + 1); + uf->textbufinfo = MEM_mallocN(final_size, __func__); + memcpy(uf->textbufinfo, ef->textbufinfo, final_size); - *((short *)(str + 0)) = ef->pos; - *((short *)(str + 2)) = ef->len; + uf->pos = ef->pos; + uf->len = ef->len; - return str; + return uf; } -static void free_undoFont(void *strv) +static void free_undoFont(void *uf_v) { - MEM_freeN(strv); + UndoFont *uf = uf_v; + MEM_freeN(uf->textbuf); + MEM_freeN(uf->textbufinfo); + MEM_freeN(uf); } static void *get_undoFont(bContext *C) |