From 3330c9979afdf9700b6220508b5f1372fa14bde2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Tue, 22 Apr 2025 11:35:12 +0200 Subject: [PATCH] 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) --- src/dispnew.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 -- 2.39.5