From 81e086788d2ed3a4d5fd525cc3750f1a1ffc9a67 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Mon, 13 Jun 2022 21:49:36 +0200 Subject: [PATCH] Avoid making new allocation to clear the screen. (#420) Previously, a new 2D vector was allocated for every new frame. This caused a lot of temporary allocation to be made. This patch modify "Screen::Clear" so that it do make a new allocation, but clear the existing one instead. Bug:https://github.com/ArthurSonzogni/FTXUI/issues/290#issuecomment-1153327251 --- src/ftxui/screen/screen.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index c3d95559..130d88f1 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -487,8 +487,11 @@ std::string Screen::ResetPosition(bool clear) const { /// @brief Clear all the pixel from the screen. void Screen::Clear() { - pixels_ = std::vector>(dimy_, - std::vector(dimx_, Pixel())); + for (auto& line : pixels_) { + for (auto& cell : line) { + cell = Pixel(); + } + } cursor_.x = dimx_ - 1; cursor_.y = dimy_ - 1; }