screen: simplify wp->w_lines allocation logic

This commit is contained in:
Björn Linse
2019-01-26 18:14:53 +01:00
parent 30bd1c1e85
commit de16c0bf64
2 changed files with 7 additions and 40 deletions

View File

@@ -5909,14 +5909,18 @@ void win_grid_alloc(win_T *wp)
grid_invalidate(grid);
}
if (grid->Rows != rows) {
wp->w_lines_valid = 0;
xfree(wp->w_lines);
wp->w_lines = xcalloc(rows+1, sizeof(wline_T));
}
int was_resized = false;
if ((has_allocation != want_allocation)
|| grid->Rows != rows
|| grid->Columns != cols) {
if (want_allocation) {
grid_alloc(grid, rows, cols, true);
win_free_lsize(wp);
win_alloc_lines(wp);
} else {
// Single grid mode, all rendering will be redirected to default_grid.
// Only keep track of the size and offset of the window.
@@ -6007,23 +6011,11 @@ retry:
// If anything fails, make grid arrays NULL, so we don't do anything!
// Continuing with the old arrays may result in a crash, because the
// size is wrong.
FOR_ALL_TAB_WINDOWS(tp, wp) {
win_free_lsize(wp);
}
if (aucmd_win != NULL)
win_free_lsize(aucmd_win);
grid_alloc(&default_grid, Rows, Columns, !doclear);
StlClickDefinition *new_tab_page_click_defs = xcalloc(
(size_t)Columns, sizeof(*new_tab_page_click_defs));
FOR_ALL_TAB_WINDOWS(tp, wp) {
win_alloc_lines(wp);
}
if (aucmd_win != NULL && aucmd_win->w_lines == NULL) {
win_alloc_lines(aucmd_win);
}
clear_tab_page_click_defs(tab_page_click_defs, tab_page_click_defs_size);
xfree(tab_page_click_defs);

View File

@@ -3891,7 +3891,6 @@ static win_T *win_alloc(win_T *after, int hidden)
// allocate window structure and linesizes arrays
win_T *new_wp = xcalloc(1, sizeof(win_T));
win_alloc_lines(new_wp);
new_wp->handle = ++last_win_id;
handle_register_window(new_wp);
@@ -3972,7 +3971,7 @@ win_free (
}
}
win_free_lsize(wp);
xfree(wp->w_lines);
for (i = 0; i < wp->w_tagstacklen; ++i)
xfree(wp->w_tagstack[i].tagname);
@@ -4119,30 +4118,6 @@ static void frame_remove(frame_T *frp)
}
/*
* Allocate w_lines[] for window "wp".
*/
void win_alloc_lines(win_T *wp)
{
wp->w_lines_valid = 0;
assert(wp->w_height_inner >= 0);
// TODO(bfredl): this should work, add call to win_set_inner_size?
// wp->w_lines = xcalloc(wp->w_height_inner+1, sizeof(wline_T));
wp->w_lines = xcalloc(MAX(wp->w_height_inner + 1, Rows), sizeof(wline_T));
}
/*
* free lsize arrays for a window
*/
void win_free_lsize(win_T *wp)
{
// TODO: why would wp be NULL here?
if (wp != NULL) {
xfree(wp->w_lines);
wp->w_lines = NULL;
}
}
/*
* Called from win_new_shellsize() after Rows changed.
* This only does the current tab page, others must be done when made active.