From 95851a05bc6b8aa11b0963f56feb2ca887ad5543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Tue, 24 Feb 2026 09:18:15 +0800 Subject: [PATCH] Remove redundant calculation code in `RichTextLabel::_get_line_max_width()` Since `_shape_line()` is called recursively, nested tables will be calculated first, so there is no need to calculate the `max_width` of the columns of the nested table in `_get_line_max_width()` again. --- scene/gui/rich_text_label.cpp | 17 +---------------- scene/gui/rich_text_label.h | 1 - 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 0d48365e2d..18233d9d22 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -586,21 +586,7 @@ int RichTextLabel::_get_line_max_width(ItemFrame *p_frame, int p_line) const { const int col_count = table->columns.size(); max_width += theme_cache.table_h_separation * col_count; - if (table->column_max_width_dirty) { - int idx = 0; - for (Item *E : table->subitems) { - ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames. - ItemFrame *frame = static_cast(E); - int column = idx % col_count; - ItemTable::Column &C = table->columns[column]; - for (int i = 0; i < (int)frame->lines.size(); i++) { - C.max_width = MAX(C.max_width, _get_line_max_width(frame, i)); - } - idx++; - } - table->column_max_width_dirty = false; - } - + // The columns in the nested table have already been calculated in _shape_line(). for (ItemTable::Column &C : table->columns) { max_width += C.max_width; } @@ -756,7 +742,6 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref table->columns[i].width = 0; } - table->column_max_width_dirty = true; // Compute minimum width for each cell. int idx = 0; for (Item *E : table->subitems) { diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index f28e91682c..fb7b43438b 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -406,7 +406,6 @@ private: int width_with_padding = 0; }; - bool column_max_width_dirty = true; LocalVector columns; LocalVector rows; LocalVector rows_baseline;