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
This commit is contained in:
Arthur Sonzogni 2022-06-13 21:49:36 +02:00 committed by GitHub
parent 925a7578d4
commit 81e086788d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<std::vector<Pixel>>(dimy_,
std::vector<Pixel>(dimx_, Pixel()));
for (auto& line : pixels_) {
for (auto& cell : line) {
cell = Pixel();
}
}
cursor_.x = dimx_ - 1;
cursor_.y = dimy_ - 1;
}