From: Gerd Möllmann Date: Tue, 22 Apr 2025 09:35:12 +0000 (+0200) Subject: Realloc less often in adjust_glyph_matrix (bug#77961) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3330c9979afdf9700b6220508b5f1372fa14bde2;p=emacs.git Realloc less often in adjust_glyph_matrix (bug#77961) * src/dispnew.c (adjust_glyph_matrix): Only xnrealloc when the glyph matrix got wider or taller. (cherry picked from commit 871ec9615a949e967bf7d19466eb9c56ed80ff7e) --- diff --git a/src/dispnew.c b/src/dispnew.c index ff14efe0c4a..9257bb71774 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -503,13 +503,17 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y while (row < end) { - row->glyphs[LEFT_MARGIN_AREA] - = xnrealloc (row->glyphs[LEFT_MARGIN_AREA], - dim.width, sizeof (struct glyph)); - /* We actually need to clear only the 'frame' member, but - it's easier to clear everything. */ - memset (row->glyphs[LEFT_MARGIN_AREA], 0, - dim.width * sizeof (struct glyph)); + /* Only realloc if matrix got wider or taller (bug#77961). */ + if (dim.width > matrix->matrix_w || new_rows) + { + row->glyphs[LEFT_MARGIN_AREA] + = xnrealloc (row->glyphs[LEFT_MARGIN_AREA], + dim.width, sizeof (struct glyph)); + /* We actually need to clear only the 'frame' member, but + it's easier to clear everything. */ + memset (row->glyphs[LEFT_MARGIN_AREA], 0, + dim.width * sizeof (struct glyph)); + } if ((row == matrix->rows + dim.height - 1 /* The mode line, if displayed, never has marginal