revert: "shada/context: fully remove jumplist duplicates #10898" (#21874)

This reverts commit 8b8ecf44f2.
It is causing performance problems on exit.
Fix #21082.
This commit is contained in:
zeertzjq 2023-01-23 19:32:27 +08:00 committed by GitHub
parent 0371d0f7af
commit 3b75485043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 25 deletions

View File

@ -1380,18 +1380,21 @@ void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long c
// When deleting lines, this may create duplicate marks in the // When deleting lines, this may create duplicate marks in the
// jumplist. They will be removed here for the specified window. // jumplist. They will be removed here for the specified window.
// When "checktail" is true, removes tail jump if it matches current position. // When "loadfiles" is true first ensure entries have the "fnum" field set
void cleanup_jumplist(win_T *wp, bool checktail) // (this may be a bit slow).
void cleanup_jumplist(win_T *wp, bool loadfiles)
{ {
int i; int i;
// Load all the files from the jump list. This is if (loadfiles) {
// needed to properly clean up duplicate entries, but will take some // If specified, load all the files from the jump list. This is
// time. // needed to properly clean up duplicate entries, but will take some
for (i = 0; i < wp->w_jumplistlen; i++) { // time.
if ((wp->w_jumplist[i].fmark.fnum == 0) for (i = 0; i < wp->w_jumplistlen; i++) {
&& (wp->w_jumplist[i].fmark.mark.lnum != 0)) { if ((wp->w_jumplist[i].fmark.fnum == 0)
fname2fnum(&wp->w_jumplist[i]); && (wp->w_jumplist[i].fmark.mark.lnum != 0)) {
fname2fnum(&wp->w_jumplist[i]);
}
} }
} }
@ -1439,8 +1442,8 @@ void cleanup_jumplist(win_T *wp, bool checktail)
// When pointer is below last jump, remove the jump if it matches the current // When pointer is below last jump, remove the jump if it matches the current
// line. This avoids useless/phantom jumps. #9805 // line. This avoids useless/phantom jumps. #9805
if (checktail && wp->w_jumplistlen if (loadfiles // otherwise (i.e.: Shada), last entry should be kept
&& wp->w_jumplistidx == wp->w_jumplistlen) { && wp->w_jumplistlen && wp->w_jumplistidx == wp->w_jumplistlen) {
const xfmark_T *fm_last = &wp->w_jumplist[wp->w_jumplistlen - 1]; const xfmark_T *fm_last = &wp->w_jumplist[wp->w_jumplistlen - 1];
if (fm_last->fmark.fnum == curbuf->b_fnum if (fm_last->fmark.fnum == curbuf->b_fnum
&& fm_last->fmark.mark.lnum == wp->w_cursor.lnum) { && fm_last->fmark.mark.lnum == wp->w_cursor.lnum) {

View File

@ -2667,8 +2667,6 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, ShaDaReadDef
} }
// Initialize jump list // Initialize jump list
setpcmark();
cleanup_jumplist(curwin, false);
wms->jumps_size = shada_init_jumps(wms->jumps, &removable_bufs); wms->jumps_size = shada_init_jumps(wms->jumps, &removable_bufs);
const bool search_highlighted = !(no_hlsearch const bool search_highlighted = !(no_hlsearch
@ -4038,13 +4036,11 @@ static bool shada_removable(const char *name)
static inline size_t shada_init_jumps(PossiblyFreedShadaEntry *jumps, static inline size_t shada_init_jumps(PossiblyFreedShadaEntry *jumps,
khash_t(bufset) *const removable_bufs) khash_t(bufset) *const removable_bufs)
{ {
if (!curwin->w_jumplistlen) { // Initialize jump list
return 0;
}
size_t jumps_size = 0; size_t jumps_size = 0;
const void *jump_iter = NULL; const void *jump_iter = NULL;
setpcmark();
cleanup_jumplist(curwin, false);
do { do {
xfmark_T fm; xfmark_T fm;
jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm); jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm);
@ -4117,7 +4113,6 @@ void shada_encode_jumps(msgpack_sbuffer *const sbuf)
khash_t(bufset) removable_bufs = KHASH_EMPTY_TABLE(bufset); khash_t(bufset) removable_bufs = KHASH_EMPTY_TABLE(bufset);
find_removable_bufs(&removable_bufs); find_removable_bufs(&removable_bufs);
PossiblyFreedShadaEntry jumps[JUMPLISTSIZE]; PossiblyFreedShadaEntry jumps[JUMPLISTSIZE];
cleanup_jumplist(curwin, true);
size_t jumps_size = shada_init_jumps(jumps, &removable_bufs); size_t jumps_size = shada_init_jumps(jumps, &removable_bufs);
msgpack_packer packer; msgpack_packer packer;
msgpack_packer_init(&packer, sbuf, msgpack_sbuffer_write); msgpack_packer_init(&packer, sbuf, msgpack_sbuffer_write);

View File

@ -1807,9 +1807,11 @@ describe('API', function()
}, },
['jumps'] = eval(([[ ['jumps'] = eval(([[
filter(map(getjumplist()[0], 'filter( filter(map(add(
{ "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }),
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') 'filter(
{ "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum },
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)')
]]):gsub('\n', '')), ]]):gsub('\n', '')),
['bufs'] = eval([[ ['bufs'] = eval([[

View File

@ -287,9 +287,11 @@ describe('context functions', function()
local with_jumps = { local with_jumps = {
['jumps'] = eval(([[ ['jumps'] = eval(([[
filter(map(getjumplist()[0], 'filter( filter(map(add(
{ "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }),
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') 'filter(
{ "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum },
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)')
]]):gsub('\n', '')) ]]):gsub('\n', ''))
} }