From bfc35ae2d97324fd3ec61d9f8fec4fac3ded90fa Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 28 Jul 2023 15:59:24 +1000 Subject: [PATCH] discard commcache. The idea here was to accelerate repeated calls to the one request, so we didn't need to repeat the search up the pane tree, or for the comm in the keymap. However I since decided that it is generally best to avoid repeated calls like this, and mostly we do. Signed-off-by: NeilBrown --- DOC/TODO.md | 17 +++++++++++- core-doc.c | 5 ++-- core-pane.c | 40 +++++++++++----------------- core-pane.h | 14 +--------- core.h | 77 ++++++++++++----------------------------------------- doc-docs.c | 2 +- 6 files changed, 53 insertions(+), 102 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index ddb82838..c6a18901 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -91,7 +91,7 @@ Requirements for a v1.0 release Core features ------------- -- [ ] Discard ccache ?? +- [X] Discard ccache ?? - [ ] Ensure all panes that should use "Free" properly, and find some what to encourage its use. - [ ] Add optional unit-test interface for modules. This should be @@ -187,6 +187,21 @@ Core features Module features --------------- +### render-stack + + My idea is to have a generic rendering pane which draws row or column + of other panes. Maybe a doc-list describes those panes with attrs + identifying the doc, the pos in the doc, the view. + Marks only identify the panes, not anything in the pane. (maybe). + I want to use this for: + - menu bar - as stack of menu triggers + - presenter thumbnails + - image thumbnails + + However this *could* be render-lines which stacks lib-renderline + panes all on the same document. This wouldn't use an attribute to + identify the location in the doc, so I'm not 100% sure of this + ### lib-askpass - [ ] have askpass tell shellmode (and others) about the SSH_ASKPASS* diff --git a/core-doc.c b/core-doc.c index a4c178a9..7030511d 100644 --- a/core-doc.c +++ b/core-doc.c @@ -863,7 +863,6 @@ DEF_CMD(doc_default_content) * accurate mark. */ struct mark *m = ci->mark; - struct commcache dchar = CCINIT; int nxt; char *cmd = "doc:char"; @@ -873,11 +872,11 @@ DEF_CMD(doc_default_content) if (strcmp(ci->key, "doc:content-bytes") == 0) cmd = "doc:byte"; - nxt = ccall(&dchar, cmd, ci->home, 1, m); + nxt = call(cmd, ci->home, 1, m); while (nxt > 0 && nxt != CHAR_RET(WEOF) && (!ci->mark2 || mark_ordered_or_same(m, ci->mark2)) && comm_call(ci->comm2, "consume", ci->home, (nxt & 0x1FFFF), m) > 0) - nxt = ccall(&dchar, cmd, ci->home, 1, m); + nxt = call(cmd, ci->home, 1, m); mark_free(m); return nxt < 0 ? nxt : 1; diff --git a/core-pane.c b/core-pane.c index a76fbe4c..0ff75cf6 100644 --- a/core-pane.c +++ b/core-pane.c @@ -922,14 +922,13 @@ struct pane *do_call_pane(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_simple; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); if (cr.ret < 0) return NULL; return cr.p; @@ -940,14 +939,13 @@ struct mark *do_call_mark(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_simple; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); if (cr.ret < 0) return NULL; return cr.m; @@ -958,14 +956,13 @@ struct mark *do_call_mark2(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_simple; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); if (cr.ret < 0) return NULL; return cr.m2; @@ -976,14 +973,13 @@ struct command *do_call_comm(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_comm; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); if (cr.ret < 0) return NULL; return cr.comm; @@ -994,14 +990,13 @@ char *do_call_strsave(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_simple; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); return cr.s; } @@ -1010,14 +1005,13 @@ struct call_return do_call_all(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_simple; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); return cr; } @@ -1026,14 +1020,13 @@ char *do_call_str(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_str; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); if (cr.ret < 0) { free(cr.s); return NULL; @@ -1046,14 +1039,13 @@ struct call_return do_call_bytes(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct call_return cr = {}; cr.c = take_bytes; cr.ret = do_call_val(type, home, comm2a, key, focus, num, m, str, - num2, m2, str2, x, y, &cr.c, ccache); + num2, m2, str2, x, y, &cr.c); if (cr.ret < 0) { free(cr.s); cr.s = NULL; diff --git a/core-pane.h b/core-pane.h index 24ce3ec6..60a3e58e 100644 --- a/core-pane.h +++ b/core-pane.h @@ -97,8 +97,7 @@ static inline int do_call_val(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *ccache) + int x, int y, struct command *comm2b) { struct cmd_info ci = {.key = key, .focus = focus, .home = focus, .num = num, .mark = m, .str = str, @@ -120,12 +119,6 @@ static inline int do_call_val(enum target_type type, struct pane *home, ci.home = home; /* fall-through */ case TYPE_focus: - if (ccache) { - if ((void*)ccache->home) - ci.home = ccache->home; - if ((void*)ccache->comm) - ci.comm = ccache->comm; - } ret = key_handle(&ci); break; case TYPE_pane: @@ -146,12 +139,7 @@ static inline int do_call_val(enum target_type type, struct pane *home, ci.comm = comm2a; ci.comm2 = comm2b; ret = ci.comm->func(&ci); - ccache = NULL; break; } - if (ccache) { - ccache->comm = ci.comm; - ccache->home = ci.home; - } return ret; } diff --git a/core.h b/core.h index baab64ec..bd5aa6e9 100644 --- a/core.h +++ b/core.h @@ -387,12 +387,6 @@ struct cmd_info { unsigned int *hash; }; -struct commcache { - struct pane *home safe; - struct command *comm safe; -}; -#define CCINIT {safe_cast 0, safe_cast 0} - #define NO_NUMERIC (INT_MAX/2) #define RPT_NUM(ci) ((ci)->num == NO_NUMERIC ? 1 : \ (ci)->num == NO_NUMERIC + 1 ? 4 : \ @@ -629,57 +623,49 @@ struct pane *do_call_pane(enum target_type type, struct pane *home, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); struct mark *do_call_mark(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); struct mark *do_call_mark2(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); struct command *do_call_comm(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); struct call_return do_call_all(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); char *do_call_str(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); struct call_return do_call_bytes(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); char *do_call_strsave(enum target_type type, struct pane *home, struct command *comm2a, const char *key safe, struct pane *focus safe, int num, struct mark *m, const char *str, int num2, struct mark *m2, const char *str2, - int x, int y, struct command *comm2b, - struct commcache *cache); + int x, int y, struct command *comm2b); #define T_focus(_p, _c) _p #define T_home(_p, _c) _p @@ -692,64 +678,35 @@ char *do_call_strsave(enum target_type type, struct pane *home, #define CALL15(ret, t_type, target, key, comm2a, focus, num, mark, str, \ num2, mark2, str2, x, y, comm2) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2,target), \ - key, focus, num, mark, str, num2, mark2, str2, x, y, comm2, NULL) + key, focus, num, mark, str, num2, mark2, str2, x, y, comm2) #define CALL14(ret, t_type, target, key, comm2a, focus, num, mark, str, num2, mark2, str2, x, y) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, mark2, str2, x, y, NULL, NULL) + key, focus, num, mark, str, num2, mark2, str2, x, y, NULL) #define CALL12(ret, t_type, target, key, comm2a, focus, num, mark, str, num2, mark2, str2) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, mark2, str2, 0, 0, NULL, NULL) + key, focus, num, mark, str, num2, mark2, str2, 0, 0, NULL) #define CALL11(ret, t_type, target, key, comm2a, focus, num, mark, str, num2, mark2) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, mark2, NULL, 0, 0, NULL, NULL) + key, focus, num, mark, str, num2, mark2, NULL, 0, 0, NULL) #define CALL10(ret, t_type, target, key, comm2a, focus, num, mark, str, num2) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, NULL, NULL, 0, 0, NULL, NULL) + key, focus, num, mark, str, num2, NULL, NULL, 0, 0, NULL) #define CALL9(ret, t_type, target, key, comm2a, focus, num, mark, str) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, 0, NULL, NULL, 0, 0, NULL, NULL) + key, focus, num, mark, str, 0, NULL, NULL, 0, 0, NULL) #define CALL8(ret, t_type, target, key, comm2a, focus, num, mark) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, NULL, 0, NULL, NULL, 0, 0, NULL, NULL) + key, focus, num, mark, NULL, 0, NULL, NULL, 0, 0, NULL) #define CALL7(ret, t_type, target, key, comm2a, focus, num) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, NULL, NULL, 0, NULL, NULL, 0, 0, NULL, NULL) + key, focus, num, NULL, NULL, 0, NULL, NULL, 0, 0, NULL) #define CALL6(ret, t_type, target, key, comm2a, focus) \ do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, 0, NULL, NULL, 0, NULL, NULL, 0, 0, NULL, NULL) + key, focus, 0, NULL, NULL, 0, NULL, NULL, 0, 0, NULL) #define CALL(ret, t_type, target, key, ...) _doCALL(ret, t_type, target, key, NULL, __VA_ARGS__) -#define _CCALL(...) VFUNC(CCALL, __VA_ARGS__) -#define CCALL15(ccache, ret, t_type, target, key, comm2a, focus, num, mark, str, num2, mark2, str2, x, y) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, mark2, str2, x, y, NULL, ccache) -#define CCALL13(ccache, ret, t_type, target, key, comm2a, focus, num, mark, str, num2, mark2, str2) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, mark2, str2, 0, 0, NULL, ccache) -#define CCALL12(ccache, ret, t_type, target, key, comm2a, focus, num, mark, str, num2, mark2) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, mark2, NULL, 0, 0, NULL, ccache) -#define CCALL11(ccache, ret, t_type, target, key, comm2a, focus, num, mark, str, num2) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, num2, NULL, NULL, 0, 0, NULL, ccache) -#define CCALL10(ccache, ret, t_type, target, key, comm2a, focus, num, mark, str) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, str, 0, NULL, NULL, 0, 0, NULL, ccache) -#define CCALL9(ccache, ret, t_type, target, key, comm2a, focus, num, mark) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, mark, NULL, 0, NULL, NULL, 0, 0, NULL, ccache) -#define CCALL8(ccache, ret, t_type, target, key, comm2a, focus, num) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, num, NULL, NULL, 0, NULL, NULL, 0, 0, NULL, ccache) -#define CCALL7(ccache, ret, t_type, target, key, comm2a, focus) \ - do_call_##ret(TYPE_##t_type, CH(T_##t_type,target, NULL), CH(T_##t_type,comm2a,target), \ - key, focus, 0, NULL, NULL, 0, NULL, NULL, 0, 0, NULL, ccache) - -#define CCALL(ccache, ret, t_type, target, key, ...) _CCALL(ccache, ret, t_type, target, key, NULL, __VA_ARGS__) - #define call(key, _focus, ...) CALL(val, focus, _focus, key, _focus, ##__VA_ARGS__) -#define ccall(ccache, key, _focus, ...) CCALL(ccache, val, focus, _focus, key, _focus, ##__VA_ARGS__) /* comm_call() is only for callbacks, is it doesn't allow a separate 'home' */ #define comm_call(_comm, key, ...) CALL(val, comm, _comm, key, ##__VA_ARGS__) #define comm_call_ret(_ret, _comm, key, ...) CALL(_ret, comm, _comm, key, ##__VA_ARGS__) diff --git a/doc-docs.c b/doc-docs.c index 97c758f5..d268d2bf 100644 --- a/doc-docs.c +++ b/doc-docs.c @@ -871,7 +871,7 @@ DEF_CB(docs_callback_lookup) ci->key, ci->focus, ci->num, ci->mark, ci->str, ci->num2, ci->mark2, ci->str2, - ci->x, ci->y, ci->comm2, NULL); + ci->x, ci->y, ci->comm2); } DEF_CMD(attach_docs) -- 2.39.5