comparison src/ui.c @ 17506:74b6674b99fd v8.1.1751

patch 8.1.1751: when redrawing popups plines_win() may be called often commit https://github.com/vim/vim/commit/9d5ffceb3fea247a88d4d3936e97b7f488aab6ff Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 26 21:01:29 2019 +0200 patch 8.1.1751: when redrawing popups plines_win() may be called often Problem: When redrawing popups plines_win() may be called often. Solution: Pass a cache to mouse_comp_pos().
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Jul 2019 21:15:06 +0200
parents 09fa437d33d8
children 696030820746
comparison
equal deleted inserted replaced
17505:a76219d230b3 17506:74b6674b99fd
3379 ) 3379 )
3380 mouse_char = ' '; 3380 mouse_char = ' ';
3381 #endif 3381 #endif
3382 3382
3383 /* compute the position in the buffer line from the posn on the screen */ 3383 /* compute the position in the buffer line from the posn on the screen */
3384 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) 3384 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum, NULL))
3385 mouse_past_bottom = TRUE; 3385 mouse_past_bottom = TRUE;
3386 3386
3387 /* Start Visual mode before coladvance(), for when 'sel' != "old" */ 3387 /* Start Visual mode before coladvance(), for when 'sel' != "old" */
3388 if ((flags & MOUSE_MAY_VIS) && !VIsual_active) 3388 if ((flags & MOUSE_MAY_VIS) && !VIsual_active)
3389 { 3389 {
3427 3427
3428 // Functions also used for popup windows. 3428 // Functions also used for popup windows.
3429 #if defined(FEAT_MOUSE) || defined(FEAT_TEXT_PROP) || defined(PROTO) 3429 #if defined(FEAT_MOUSE) || defined(FEAT_TEXT_PROP) || defined(PROTO)
3430 3430
3431 /* 3431 /*
3432 * Compute the position in the buffer line from the posn on the screen in 3432 * Compute the buffer line position from the screen position "rowp" / "colp" in
3433 * window "win". 3433 * window "win".
3434 * "plines_cache" can be NULL (no cache) or an array with "win->w_height"
3435 * entries that caches the plines_win() result from a previous call. Entry is
3436 * zero if not computed yet. There must be no text or setting changes since
3437 * the entry is put in the cache.
3434 * Returns TRUE if the position is below the last line. 3438 * Returns TRUE if the position is below the last line.
3435 */ 3439 */
3436 int 3440 int
3437 mouse_comp_pos( 3441 mouse_comp_pos(
3438 win_T *win, 3442 win_T *win,
3439 int *rowp, 3443 int *rowp,
3440 int *colp, 3444 int *colp,
3441 linenr_T *lnump) 3445 linenr_T *lnump,
3446 int *plines_cache)
3442 { 3447 {
3443 int col = *colp; 3448 int col = *colp;
3444 int row = *rowp; 3449 int row = *rowp;
3445 linenr_T lnum; 3450 linenr_T lnum;
3446 int retval = FALSE; 3451 int retval = FALSE;
3454 3459
3455 lnum = win->w_topline; 3460 lnum = win->w_topline;
3456 3461
3457 while (row > 0) 3462 while (row > 0)
3458 { 3463 {
3464 int cache_idx = lnum - win->w_topline;
3465
3466 if (plines_cache != NULL && plines_cache[cache_idx] > 0)
3467 count = plines_cache[cache_idx];
3468 else
3469 {
3459 #ifdef FEAT_DIFF 3470 #ifdef FEAT_DIFF
3460 /* Don't include filler lines in "count" */ 3471 /* Don't include filler lines in "count" */
3461 if (win->w_p_diff 3472 if (win->w_p_diff
3462 # ifdef FEAT_FOLDING 3473 # ifdef FEAT_FOLDING
3463 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL) 3474 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL)
3464 # endif 3475 # endif
3465 ) 3476 )
3466 { 3477 {
3467 if (lnum == win->w_topline) 3478 if (lnum == win->w_topline)
3468 row -= win->w_topfill; 3479 row -= win->w_topfill;
3480 else
3481 row -= diff_check_fill(win, lnum);
3482 count = plines_win_nofill(win, lnum, TRUE);
3483 }
3469 else 3484 else
3470 row -= diff_check_fill(win, lnum); 3485 #endif
3471 count = plines_win_nofill(win, lnum, TRUE); 3486 count = plines_win(win, lnum, TRUE);
3472 } 3487 if (plines_cache != NULL)
3473 else 3488 plines_cache[cache_idx] = count;
3474 #endif 3489 }
3475 count = plines_win(win, lnum, TRUE);
3476 if (count > row) 3490 if (count > row)
3477 break; /* Position is in this buffer line. */ 3491 break; /* Position is in this buffer line. */
3478 #ifdef FEAT_FOLDING 3492 #ifdef FEAT_FOLDING
3479 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL); 3493 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL);
3480 #endif 3494 #endif
3624 3638
3625 if (wp != curwin) 3639 if (wp != curwin)
3626 return IN_UNKNOWN; 3640 return IN_UNKNOWN;
3627 3641
3628 /* compute the position in the buffer line from the posn on the screen */ 3642 /* compute the position in the buffer line from the posn on the screen */
3629 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum)) 3643 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum, NULL))
3630 return IN_STATUS_LINE; /* past bottom */ 3644 return IN_STATUS_LINE; /* past bottom */
3631 3645
3632 mpos->col = vcol2col(wp, mpos->lnum, col); 3646 mpos->col = vcol2col(wp, mpos->lnum, col);
3633 3647
3634 if (mpos->col > 0) 3648 if (mpos->col > 0)