From 570ab663b7f5b974438a7d6f5fbeb07b91339043 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Mar 2020 14:57:14 +0400 Subject: [PATCH] Use cache for remembered last dice frames. --- .../history/view/media/history_view_sticker.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 434359764..800de02f7 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -31,12 +31,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace HistoryView { namespace { -double GetEmojiStickerZoom(not_null session) { +[[nodiscard]] double GetEmojiStickerZoom(not_null session) { return session->account().appConfig().get( "emojies_animated_zoom", 0.625); } +[[nodiscard]] QImage CacheDiceImage(int index, const QImage &image) { + static auto Cache = base::flat_map(); + const auto i = Cache.find(index); + if (i != end(Cache) && i->second.size() == image.size()) { + return i->second; + } + Cache[index] = image; + return image; +} + } // namespace Sticker::Sticker( @@ -116,7 +126,7 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) { : Lottie::Animation::FrameInfo(); if (_nextLastDiceFrame) { _nextLastDiceFrame = false; - _lastDiceFrame = frame.image; + _lastDiceFrame = CacheDiceImage(_diceIndex, frame.image); } const auto &image = _lastDiceFrame.isNull() ? frame.image